我正在使用以下代码片段来检测特定表单输入字段每次更改的情况。
$( '#textbox' ).on( 'input', function() {
// Do something here
});
这个输入框属于一个表单,里面有复选框、单选按钮和更多文本输入框。有没有办法检测到任何表单字段的更改?
$( '#textbox' ).on( 'input', function() {
// Do something here
});
这个输入框属于一个表单,里面有复选框、单选按钮和更多文本输入框。有没有办法检测到任何表单字段的更改?
试试看,
$('#Form input').on( 'input', function() {
//This would be called if any of the input element has got a change inside the form
});
<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");
});
$("form :input").change(function() {
});
$( 'form' ).on( 'input', function(e) { console.log(e.target); });
- Ram'e'
在function(e)
中的作用是什么? - henrywrighte
是事件对象,它的target
属性指向事件的目标。 - Ram