Jquery metric data changes (revised version) _ jquery

Source: Internet
Author: User
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:


Related Article

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.