I. Overview
The last section of the jquery custom extension method, I have always wanted to do with jquery to write a small plug-in, work is also used in the calendar plug-in with jquery, their own thinking to build a wheel--HTML5 mobile phone Web Calendar control, nonsense not to say, first look at it
Very simple, the code is encapsulated in jquery, the web side only needs to be called;
Ii. jquery Custom Entity objects
jquery can be custom function functions, there is no entity object can be defined, inside the encapsulation method that? Query the data found, it is possible, not only to encapsulate the properties, you can also write their own methods, call the template code as follows:
$. Calenderdata = { //Time Display button$ShowSelectData: Function () {$ ("#tcontrolretx"). Text (Tyeer +"years"+ Tmonth +"Month"+ Tday +"Day"); } , //whether a leap year is interpreted$ISLeapYear: function (year) {if((Year%4) ==0) && (Year% -) !=0) || (Year% -) ==0)) { return(true); } Else { return(false); } }, //Initialize year$InitCalenderYeerData: Function (Yeerdata, curyear) {varyeerhtml =""; varNdatatime =NewDate ();//Current Time varCurryear = Ndatatime.getfullyear ();//returns the year as a four-digit number from a Date object varnowyear; Yeerhtml+ = Lidatamodel.format (""); for(varIyee = Yeerdata; Iyee >=0; iyee--) {nowyear= Curryear-Iyee; if(Curyear = =nowyear) {yeerhtml+=Lisdatamodel.format (nowyear); } Else{yeerhtml+=Lidatamodel.format (nowyear); }} yeerhtml+ = Lidatamodel.format (""); returnyeerhtml; }}
When calling, you only need to proceed as follows:
$. Calenderdata. $ShowSelectData ();
It is also convenient to call up. After encapsulation, jquery calls appear less cluttered.
jquery Custom extension Method (ii)--html Calendar control