且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用jquery监视表单字段更改

更新时间:2023-02-19 09:38:21

在表单中添加一个类并使用它来过滤

Just add a class to the form and use it to filter

$('.form :input').each(function() {
    $(this).data('formValues', $(this).val());
});

编辑

只是一个建议,您可以将更改事件直接附加到表单

Just a suggestion, you can attach the change event directly to the form

现场演示: http://jsfiddle.net/jomanlk/kNx8p/1/

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

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

<div id='log'></div>

$('form :input').change(function(){
   $('#log').prepend('<p>Form changed</p>')
});

您可以通过添加计时器并使其每隔xx秒保存一次来轻松改善这一点。

You can easily improve this by adding a timer and making it save every xx seconds.