HTML按钮,按下时模拟按下ESC kayboard键。 因此,单击该按钮与用户在键盘上按ESC键具有相同的效果
如果无论如何肯定不可能请告诉我。
任何方法都可以。
编辑:我不想按ESC键来触发某些东西,我想要反向,触发ESC键的东西
答案 0 :(得分:2)
试用此代码
<强> JS 强>
$('body').keydown(function(e){
if (e.which==27){
alert("hh");
}
});
$('#trigger').click(function(){
var e=$.Event('keydown');
e.which=27;
$('body').trigger(e);
});
<强> HTML 强>
<input type="button" id="trigger" value="trigger button" />
<强> DEMO HERE 强>
答案 1 :(得分:0)
使用JQuery,您可以创建Key Press Event
并将该事件与Button Click
绑定。像:
<input type="button" id="esc" value="Esc like button">
<script>
$('body').keydown(function(e) {
if (e.keyCode == 27) {
// put your code here if any (that will run after Esc pressed).
alert('Esc Pressed');
}
});
var e = $.Event("keydown", {
keyCode: 27
});
$('#esc').click(function() {
$("body").trigger(e);
});
</script>