jquery trigger event

前端 未结 3 1273
误落风尘
误落风尘 2021-01-26 09:40

How can we call the trigger click event on a live object.

$(\"#continue\").live(\"keypress\",function(){
 if (e.which == 32 || e.which == 13) {
    $(this).trigg         


        
3条回答
  •  隐瞒了意图╮
    2021-01-26 10:00

    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?

提交回复
热议问题