The development of jquery common function collection, welcome everyone to exchange study
(function ($) { /************************** Get the parameters of the URL ************************************/ //parameter: The parameter name in the URL //return value: The value of this parameter$.geturlparam =function(name) {varReg =NewRegExp ("(^|&)" + name + "= ([^&]*) (&|$)"); varr = Window.location.search.substr (1). Match (REG); if(r! =NULL)returnUnescape (r[2]);return NULL; } /**************************************************************/ /********************** date formatting ****************************************/$.dateformatter=function(date) {if(!date) {return‘‘; } vary =date.getfullyear (); varm = date.getmonth () + 1; varD =date.getdate (); returnY + '-' + (M < 10?) (' 0 ' + m): m) + '-' + (D < 10?) (' 0 ' +d): D); } $.dateparser=function(s) {if(!s) {return NULL; } varSS = S.split ('-'); vary = parseint (ss[0], 10); varm = parseint (Ss[1], 10); varD = parseint (ss[2], 10); if(!isnan (Y) &&!isnan (m) &&!IsNaN (d)) { return NewDate (Y, m-1, D); } Else { return NewDate (); }} $.jsondatetodatetime=function(jsondate) {//Convert JSON date to stringJsondate = Jsondate.split (' (') [1].split (') ') [0]; varRdate =NewDate (parseint (jsondate)); returnrdate.tolocalestring (); } //Description: Format the current time, format the parameter, return the formatted string //specific format: YYYY-MM-DD hh:mm:ss | yyyy mm month DD day hh hours mm min ss sec | yyyy mm month DD Day //mm/dd/yyyy | yyyyMMdd | yyyy-mm-dd HH:MM:SS | YYYYMMDDHHMMSS etc.$.formatnowdate =function(format) {varMyDate =NewDate (); varo = { "m+": Mydate.getmonth () + 1,//Month"D+": mydate.getdate (),// Day"H +": mydate.gethours (),//Hour"m+": mydate.getminutes (),//minute"S+": Mydate.getseconds (),//Second"q+": Math.floor ((Mydate.getmonth () + 3)/3),//Quarter"S": Mydate.getmilliseconds ()//Millisecond } if(/(y+)/. Test (format)) {Format= Format.replace (Regexp.$1, (mydate.getfullyear () + ""). substr (4-regexp.$1. length)); } for(varKincho) {if(NewRegExp ("(" + K + ")"). Test (format)) {format= Format.replace (regexp.$1, regexp.$1.length = = 1? O[k]: ("XX" + o[k]). substr ("" +O[k]) (length)); } } returnformat; } /**************************************************************/ /************************** generating guid************************************/$.newguid=function () { This. val (' Xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx '. Replace (/[xy]/G,function(c) {varR = Math.random () * 16 | 0, v = c = = ' x '? R:r & 0x3 | 0x8; returnV.tostring (16); })); return This; }; /**************************************************************/}) (jQuery);
Common function Extensions of jquery