///
(function($) {
/*Monitor whether the page data changes*/
var pageDataChange = false;
var tagName = "Input, Select, Textarea" ;
var ctrlIds = [];
$.fn.MonitorDataChange = function(options) {
var deafult = {
arrTags: tagName, //The tagName attribute of the control to be monitored
arrCtrls : ctrlIds //Unmonitored control ID
};
var ops = $.extend(deafult, options);
tagName = ops.arrTags;
ctrlIds = ops.arrCtrls;
/*Cache the element data when the element gets focus for the first time*/
$(ops.arrTags).one("focus", function() {
if ($.inArray($(this).attr ("id"), ops.arrCtrls) != -1) {
return;
}
$(this).data('initData', $(this).val());
});
};
/*Get whether the page data has changed*/
$.fn.isChange = function() {
$(tagName).each(function() {
if ($.inArray($(this).attr("id"), ctrlIds) != -1) {
return;
}
/*If the element's initData caches data It is defined and not equal to its value, indicating that the data in the page has changed*/
if (typeof ($(this).data('initData')) != 'undefined') {
if ( $(this).data('initData') != $(this).val()) {
pageDataChange = true;
}
}
});
return pageDataChange;
};
})(jQuery);
Foreground call:
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn