使用jQuery检测表单中的数据更改 [英] Detecting data changes in forms using jQuery

查看:142
本文介绍了使用jQuery检测表单中的数据更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有母版页的ASP.NET 2.0,我想知道是否有人知道如何检测某个< div> 或 fieldset 已更改(例如,标记为' IsDirty ')?

I'm using ASP.NET 2.0 with a Master Page, and I was wondering if anyone knew of a way to detect when the fields within a certain <div> or fieldset have been changed (e.g., marked 'IsDirty')?

推荐答案

您可以为所有输入绑定Change事件,并将变量标记为true。像这样。

You could bind the Change event for all inputs and flag a variable as true. Like this.

var somethingChanged = false;
$(document).ready(function() { 
   $('input').change(function() { 
        somethingChanged = true; 
   }); 
});

但是,请记住,如果用户更改某些内容,则更改回原始值,仍会被标记为已更改。

But, keep in mind that if the user changes something, then changes back to the original values, it will still be flagged as changed.

更新:对于特定的div或fieldset。只需使用给定fieldset或div的id。示例:

UPDATE: For a specific div or fieldset. Just use the id for the given fieldset or div. Example:

var somethingChanged = false;
$(document).ready(function() { 
   $('#myDiv input').change(function() { 
        somethingChanged = true; 
   }); 
});

这篇关于使用jQuery检测表单中的数据更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆