如何使用jQuery检测任何表单输入字段的更改?

时间:2014-07-15 13:36:00

标签: javascript jquery forms

每次特定表单输入字段更改时,我都会使用以下代码段进行检测。

$( '#textbox' ).on( 'input', function() {
    // Do something here
});

此特定输入字段属于具有复选框,单选按钮和更多文本输入字段的表单。有没有办法检测何时对表单的任何字段进行更改?

3 个答案:

答案 0 :(得分:9)

尝试,

$('#Form input').on( 'input', function() {
  //This would be called if any of the input element has got a change inside the form
}); 

答案 1 :(得分:6)

试试这个:

<强> HTML:

<form>
    <p><input type='text' /></p>
    <p><input type='text' /></p>
    <p><input type='checkbox' /></p>
</form>

<强> JQuery的:

$('form :input').change(function(){
   alert("Form changed");
});

<强> JSFiddle Demo

答案 2 :(得分:3)

$("form :input").change(function() {

});