This article illustrates how jquery uses the OOP mode class class. Share to everyone for your reference, specific as follows:
I find it convenient to use class to manage the various function of jquery, and the code is very readable. I used to like to build file writing function, and then include files, then find a function is more trouble. No class is used to manage function convenience. Crap said no more.
First, oop.html
<! DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
Two, build a oop.js
function oop () {//define variable var AAA = this;
Initialize this.init = function () {aaa.addnotice ();
Aaa.unchange ();
return AAA; //Add function This.addnotice = function () {$ ("input[type= ' text ']"). each (function () {$ (this). Focus (FU
Nction () {if (). val () = = $ (this). attr (' notice ')) {$ (")". Val ("");
. blur (function () {if (). val () = $ (this). attr (' notice ') | | $.trim ($ (this). val ()) = = "") {
$ (this). Val ($ (this). attr (' notice '));
}
});
}); //Add function This.cleannotice = function () {$ ("input[type= ' text ']"). each (function () {if ($ (). val () = $
(this). attr (' notice ')} {$ (this). Val ("");
}
});
//Add function This.unchange = function () {$ ('. Select '). Bind (' Change ', function () {if ($). val () = = ' 0 ') {
Alert (' Noselect ');
}else{Alert ($ (this). Val ());
}
}); }
}
You're interested in testing yourself.
I hope this article will help you with the jquery program design.