The previous effort was in vain. The solution to these problems is to monitor whether the page data changes. If any changes occur, the system prompts you to save the changes. If the data does not change. When we click Save, we do not need to submit it to the database.
Next let's take a look at the solution:
Copy codeThe Code is as follows:
// <Reference path = "jquery-1.3.2-vsdoc2.js"/>
(Function ($ ){
Var pageDataChange = false // The page data is not changed by default.
/* Monitoring page data changes */
$. Fn. MonitorDataChange = function (options ){
Var tagName = new Array ('input', 'select', 'textarea ');
Var ctrlIds = [];
Var deafult = {
ArrTags: tagName, // The tagName attribute array of the control to be monitored
ArrCtrls: ctrlIds // unmonitored control ID
};
Var ops = $. extend (deafult, options );
For (var I = 0; I <ops. arrTags. length; I ++ ){
$ (Ops. arrTags [I]). each (function (){
If (ops. arrCtrls. length = 0 ){
$ (This). bind ('change', function (){
PageDataChange = true;
});
}
Else {
Var flag = false;
For (var j = 0; j <ops. arrCtrls. length; j ++ ){
If ($ (this). attr ('id') = ops. arrCtrls [j]) {
Flag = true;
Break;
}
}
If (! Flag ){
$ (This). bind ('change', function (){
PageDataChange = true;
});
}
}
});
}
Return this;
};
/* Whether the page data is changed */
$. Fn. getValue = function (){
Return pageDataChange;
};
}) (JQuery );