简体   繁体   English

相当于javascript onclick(this.form)的jQuery

[英]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_me(this.form)" />
etc..
</form>

The onKeyup event executes/calls the chk_me function with this.form as its parameter. onKeyup事件以this.form为参数执行/调用chk_me函数。

I need to convert that to a jQuery equivalent to something like this: 我需要将其转换为等效于jQuery的东西,如下所示:

$(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)? 也许换句话说:如何在jQuery中(或在脚本标签之间)获得this.form(完全相同)?

$(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. 注意:根据您的html结构,输入字段的选择器可能会有所不同。

$(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'));
  });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM