Jquery-based metric data changes

Source: Internet
Author: User

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 );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.