<div class="codetitle"> <span><a style="CURSOR: pointer" data="68191" class="copybut" id="copybut68191" onclick="doCopy('code68191')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code68191"> <br>///<reference path="query-1.5.1.min.js"></reference> <br>(function($) { <br>/*监控页面数据是否发生变化*/ <br>var pageDataChange = false; <br>var tagName = "Input, Select, Textarea"; <br>var ctrlIds = []; <br>$.fn.MonitorDataChange = function(options) { <br>var deafult = { <br>arrTags: tagName, //需监控控件的tagName属性 <br>arrCtrls: ctrlIds //不监控的控件ID <br>}; <br>var ops = $.extend(deafult, options); <br>tagName = ops.arrTags; <br>ctrlIds = ops.arrCtrls; <br>/*元素第一次获取焦点时缓存该元素数据*/ <br>$(ops.arrTags).one("focus", function() { <br>if ($.inArray($(this).attr("id"), ops.arrCtrls) != -1) { <br>return; <br>} <br>$(this).data('initData', $(this).val()); <br>}); <br>}; <br>/*获取页面数据是否已经改变*/ <br>$.fn.isChange = function() { <br>$(tagName).each(function() { <br>if ($.inArray($(this).attr("id"), ctrlIds) != -1) { <br>return; <br>} <br>/*如果该元素的initData缓存数据已定义并且不等于他的value值,标识该页面中数据发生变化*/ <br>if (typeof ($(this).data('initData')) != 'undefined') { <br>if ($(this).data('initData') != $(this).val()) { <br>pageDataChange = true; <br>} <br>} <br>}); <br>return pageDataChange; <br>}; <br>})(jQuery); <br> </div> <br>前台调用: <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="59905" class="copybut" id="copybut59905" onclick="doCopy('code59905')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code59905"> <br><script type="text/javascript"> <BR>var is_change = false; <BR>$(document).ready(function() { <BR>$("form").MonitorDataChange(); <BR>}); <BR>function alertMsg() { <BR>is_change = $.fn.isChange(); <BR>if(is_change){ <BR>alert('数据发生改变!'); <BR>} <BR>} <BR></script> <br><input type="text"> <br><input type="text"> <br><input type="text"> <br><input type="text"> <br><textbox runat="server"></textbox> <br><checkbox runat="server"></checkbox> <br><input type="button" value="true" onclick="alertMsg();"> <br> </div>