开发者

jquery equivalent of javascript onclick(this.form)

I currently have something like this:

<form  action="cart.php?action=update" method="post" name="cart" id="cart">
<input maxlength="3" value="25" onKeyup="chk开发者_如何学Python_me(this.form)" />
etc..
</form>

The onKeyup event executes/calls the chk_me function with this.form as its parameter.

I need to convert that to a jQuery equivalent to something like this:

$(document).ready(function(){
  $('input').keyup(function(){
     chk_me(this.form);
  }):
});

This example doesn't work ofcourse. But how can I make it work?

Maybe in other words: How can I get this.form (exactly the same) in jQuery (or perhaps between script tags)?


$(document).ready(function(){
    $('#cart input:first').keyup(function(){
        chk_me($('#cart').get(0));
    });
});

note : the selectors for the input field may vary based on your html structure.


$(document).ready(function(){
  $('#cart input').keyUp(function(){
    chk_me($('#cart')[0]);
  });
});


Try this. You should specify a name to input field and use that in the selector.

$(document).ready(function(){
  $('#cart input[name=nameOfTheField').keyup(function(){
      chk_me(this.closest('form'));
  });
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜