There are many bugs in the article I wrote before jquery's monitoring data change (revised version). I have reorganized it today. Please kindly advise
The Code is as follows:
///
(Function ($ ){
/* Monitoring 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 the focus for the first time */
$ (Ops. arrTags). one ("focus", function (){
If ($. inArray ($ (this). attr ("id"), ops. arrCtrls )! =-1 ){
Return;
}
$ (This). data ('initdata', $ (this). val ());
});
};
/* Check whether the page data has changed */
$. Fn. isChange = function (){
$ (TagName). each (function (){
If ($. inArray ($ (this). attr ("id"), ctrlIds )! =-1 ){
Return;
}
/* If the initData cached data of this element has been defined and is not equal to its value, the data on this page will change */
If (typeof ($ (this). data ('initdata '))! = 'Undefined '){
If ($ (this). data ('initdata ')! = $ (This). val ()){
PageDataChange = true;
}
}
});
Return pageDataChange;
};
}) (JQuery );
Foreground call:
The Code is as follows: