如何拥有“jQuery.Event”在 Firefox 上工作吗?
我正在编写一个脚本,当 单击按钮。
以下脚本在 IE、Safari 和 Chrome 上运行良好,但在 Firefox 和 Opera 上不起作用。即使我将 {keyCode: 37} 更改为 {which: 37},它仍然不起作用。
$('button').click(function(e){
jQuery("body").trigger(jQuery.Event("keydown", {keyCode: 37}));
e.preventDefault();
}
有谁知道如何让它在 Firefox 和 Opera 上运行?
I'm writing a script which triggers an artificial keydown event with keyCode 37 when
button is clicked.
The following script works fine on IE, Safari, and Chrome, but it doesn't work on Firefox and Opera. Even if I change {keyCode: 37} to {which: 37}, it still doesn't work.
$('button').click(function(e){
jQuery("body").trigger(jQuery.Event("keydown", {keyCode: 37}));
e.preventDefault();
}
Does anyone know how to make it work on Firefox and Opera?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个,如果浏览器不支持
which
,它将支持keyCode
try this, if a browser doesn't support
which
, it will supportkeyCode
尝试这样:
Try it this way :