开发者

jquery equivalent of javascript onclick(this.form)

开发者 https://www.devze.com 2023-04-01 18:55 出处:网络
I currently have something like this: <formaction=\"cart.php?action=update\" method=\"post\" name=\"cart\" id=\"cart\">

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

精彩评论

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