[英]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.