jquery触发事件 [英] jquery trigger event
问题描述
$(#continue)。live keypress,function(){
if(e.which == 32 || e.which == 13){
$(this).trigger(click);
}
});
当我按Enter键进入如果块,但它没有触发按钮。你能帮我帮忙吗谢谢提前。
尝试这样:
$(#continue)。live(keyup,function(e){
if(e.keyCode == 32 || e.keyCode == 13){
$(this).trigger(click);
}
});
我在这篇文章中介绍了这一点: EnterKey有时在IE8中不工作,使用jQuery的keyPressed
但是基本上有一些特殊键不会在按键上触发,您必须使用keydown或keyup。
示例这里: http://jsfiddle.net/uS4XK/1/
虽然我必须诚实,这是一个奇怪的行为想要。您想要在#continue上点击一次点击事件,当他们按Enter键?
How can we call the trigger click event on a live object.
$("#continue").live("keypress",function(){
if (e.which == 32 || e.which == 13) {
$(this).trigger("click");
}
});
when i press enter on the button it is coming into if block but it is not triggering the button. can u please help me in this. Thanks in advance.
Try this:
$("#continue").live("keyup",function(e){
if (e.keyCode == 32 || e.keyCode == 13) {
$(this).trigger("click");
}
});
I covered this in this post a bit: EnterKey is not working sometimes in IE8, using jQuery's keyPressed
But basically there are "Special Keys" that won't fire on keypress and you have to use keydown or keyup.
Example here: http://jsfiddle.net/uS4XK/1/
Though I have to be honest this is a strange behavior to want. You want a click event on #continue when they press enter in it?
这篇关于jquery触发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!