开发者

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

Using jQuery, I bind keydown globally like this:

$(document).bind('keydown', function(e) { alert('keydown fired');开发者_JAVA百科 });

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. 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. 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'); };
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜