简体   繁体   English

复选框上的keydown在FF中不会冒泡,但在IE中却会冒泡。 怎么解决?

[英]keydown on checkbox doesn't bubble in FF, but it does in IE. How to solve?

Using jQuery, I bind keydown globally like this: 使用jQuery,我像这样全局绑定keydown:

$(document).bind('keydown', function(e) { alert('keydown fired'); });

When I press a key having focused a text input field, the alert shows just fine. 当我按聚焦于文本输入字段的键时,警报显示得很好。 But when I focus a checkbox and then press a key, it does not fire. 但是,当我突出显示一个复选框然后按一个键时,它不会触发。 Not even with the keypress event. 甚至没有按键事件。 Why do these events not bubble up to the document? 为什么这些事件不会出现在文档中? They do in Internet Explorer but not in Firefox. 它们在Internet Explorer中运行,但在Firefox中不运行。 How to I fix this? 我该如何解决? I don't want to bind the keydown explicitly to th checkbox, I want to be able to use delegation. 我不想将keydown显式绑定到复选框,我希望能够使用委托。 Maybe I can't? 也许我做不到

Thx, 谢谢,

/Tommy /汤米

Try binding change. 尝试绑定更改。

$(document).bind('keydown', function(e) { alert('keydown fired'); })
.bind('change', function(e){ alert('keydown fired'); };

Although it may be better to target check boxes specifically. 尽管最好专门针对复选框。

$(document).bind('keydown', function(e) { alert('keydown fired'); });
$('input:checkbox').bind('change', function(e){ alert('keydown fired'); };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 <a href doesn't fire after .Click jquery function call in IE. Works fine with Chrome and FF - <a href doesn't fire after .Click jquery function call in IE. Works fine with Chrome and FF Javascript在IE8中不起作用,但在IE9和FF中起作用 - Javascript doesn't work in IE8, but in IE9 and FF does SWF不会在IE9中呈现(但会在Chrome / FF中呈现) - SWF doesn't render in IE9 (but does in Chrome/FF) onClick =“history.go(0)”在mozilla中不起作用但在IE中有效。 如何在Mozilla浏览器中解决此问题 - onClick=“history.go(0)” doesn't works in mozilla but works in IE. How to resolve this issue in mozilla browser ENTER keydown在IE中不起作用! 角 - ENTER keydown doesn't work in IE! Angular 为什么keydown监听器在IE中不起作用 - Why keydown listener doesn't work in IE Raphael缩小版本在IE上不起作用。 任何想法? - Raphael minify version doesn't work on IE. Any idea? 为什么在FF3中仍然选中复选框,但在IE,Chrome或 - Why does a checkbox remain checked in FF3 but not in IE, Chrome or 该脚本在IE中不起作用。 我该如何解决? - The script does not work in IE. How can I fix it? 在使用JavaScript的文本框中将自动完成功能与FF(或IE)一起使用时,如何禁用快捷键处理? - How to disable keydown processing when using autocomplete with FF (or IE) in a text box using javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM