// Clear spaces on both sides String. prototype. trim = function (){ Return this. replace (/(^ \ s *) | (\ s * $)/g ,''); }; // Merge multiple blanks into one blank String. prototype. ResetBlank = function (){ Var regEx =/\ s +/g; Return this. replace (regEx ,''); }; // Retain numbers String. prototype. GetNum = function (){ Var regEx =/[^ \ d]/g; Return this. replace (regEx ,''); }; // Retain Chinese Characters String. prototype. GetCN = function (){ Var regEx =/[^ \ u4e00-\ u9fa5 \ uf900-\ ufa2d]/g; Return this. replace (regEx ,''); }; // Convert String to Number String. prototype. ToInt = function (){ Return isNaN (parseInt (this ))? This. toString (): parseInt (this ); }; // Get the byte length String. prototype. GetLen = function (){ Var regEx =/^ [\ u4e00-\ u9fa5 \ uf900-\ ufa2d] + $ /; If (regEx. test (this )){ Return this. length * 2; } Else { Var oMatches = this. match (/[\ x00-\ xff]/g ); Var oLength = this. length * 2-oMatches. length; Return oLength; } }; // Obtain the full name of the object String. prototype. GetFileName = function (){ Var regEx =/^. * \/([^ \/\?] *). * $ /; Return this. replace (regEx, '$1 '); }; // Obtain the file extension String. prototype. GetExtensionName = function (){ Var regEx =/^. * \/[^ \/] * (\. [^ \. \?] *). * $ /; Return this. replace (regEx, '$1 '); }; // Replace all String. prototype. replaceAll = function (reallyDo, replaceWith, ignoreCase) { If (! RegExp. prototype. isPrototypeOf (reallyDo )){ Return this. replace (new RegExp (reallyDo, (ignoreCase? "Gi": "g"), replaceWith ); } Else { Return this. replace (reallyDo, replaceWith ); } }; // Format the string add By Liu Jingning String. Format = function (){ If (arguments. length = 0 ){ Return ''; } If (arguments. length = 1 ){ Return arguments [0]; } Var reg =/{(\ d + )?} /G; Var args = arguments; Var result = arguments [0]. replace (reg, function ($0, $1 ){ Return args [parseInt ($1) + 1]; }); Return result; }; // Add zero to the number Number. prototype. LenWithZero = function (oCount ){ Var strText = this. toString (); While (strText. length <oCount ){ StrText = '0' + strText; } Return strText; }; // Unicode Restoration Number. prototype. ChrW = function (){ Return String. fromCharCode (this ); }; // The number array is sorted in ascending order. Array. prototype. Min2Max = function (){ Var oValue; For (var I = 0; I <this. length; I ++ ){ For (var j = 0; j <= I; j ++ ){ If (this [I] <this [j]) { OValue = this [I]; This [I] = this [j]; This [j] = oValue; } } } Return this; }; // The number array is sorted in ascending order. Array. prototype. Max2Min = function (){ Var oValue; For (var I = 0; I <this. length; I ++ ){ For (var j = 0; j <= I; j ++ ){ If (this [I]> this [j]) { OValue = this [I]; This [I] = this [j]; This [j] = oValue; } } } Return this; }; // Obtain the largest item in the number Array Array. prototype. GetMax = function (){ Var oValue = 0; For (var I = 0; I <this. length; I ++ ){ If (this [I]> oValue ){ OValue = this [I]; } } Return oValue; }; // Obtain the smallest item in the number Array Array. prototype. GetMin = function (){ Var oValue = 0; For (var I = 0; I <this. length; I ++ ){ If (this [I] <oValue ){ OValue = this [I]; } } Return oValue; }; // Obtain the Chinese form of the current time Date. prototype. GetCNDate = function (){ Var oDateText = ''; ODateText + = this. getFullYear (). LenWithZero (4) + new Number (24180). ChrW (); ODateText + = this. getMonth (). LenWithZero (2) + new Number (26376). ChrW (); ODateText + = this. getDate (). LenWithZero (2) + new Number (26085). ChrW (); ODateText + = this. getHours (). LenWithZero (2) + new Number (26102). ChrW (); ODateText + = this. getMinutes (). LenWithZero (2) + new Number (20998). ChrW (); ODateText + = this. getSeconds (). LenWithZero (2) + new Number (31186). ChrW (); ODateText + = new Number (32 ). chrW () + new Number (32 ). chrW () + new Number (26143 ). chrW () + new Number (26399 ). chrW () + new String ('20140901 '). substr (this. getDay () * 5, 5 ). toInt (). chrW (); Return oDateText; }; // Extended Date formatting Date. prototype. Format = function (format ){ Var o = { "M +": this. getMonth () + 1, // month "D +": this. getDate (), // day "H +": this. getHours () % 12 = 0? 12: this. getHours () % 12, // hour "H +": this. getHours (), // hour "M +": this. getMinutes (), // minute "S +": this. getSeconds (), // second "Q +": Math. floor (this. getMonth () + 3)/3), // quarter "S": this. getMilliseconds () // millisecond }; Var week = { "0": "\ u65e5 ", "1": "\ u4e00 ", "2": "\ u4e8c ", "3": "\ u4e09 ", "4": "\ u56db ", "5": "\ u4e94 ", "6": "\ u516d" }; If (/(y +)/. test (format )){ Format = format. replace (RegExp. $1, (this. getFullYear () + ""). substr (4-RegExp. $1. length )); } If (/(E +)/. test (format )){ Format = format. replace (RegExp. $1, (RegExp. $1. length> 1 )? (RegExp. $1. length> 2? "\ U661f \ u671f": "\ u5468"): "") + week [this. getDay () + ""]); } For (var k in o ){ If (new RegExp ("(" + k + ")"). test (format )){ Format = format. replace (RegExp. $1, (RegExp. $1. length = 1 )? (O [k]): ("00" + o [k]). substr ("" + o [k]). length ))); } } Return format; } Date. prototype. Diff = function (interval, objDate ){ // If the parameter is insufficient or the objDate is not of the date type, the undefined will be returned. If (arguments. length <2 | objDate. constructor! = Date) {return undefined ;} Switch (interval ){ // Calculate the second difference Case's ': return parseInt (objDate-this)/1000 ); // Calculate the Score Difference Case 'N': return parseInt (objDate-this)/60000 ); // Computing time difference Case 'H': return parseInt (objDate-this)/3600000 ); // Calculate the daily difference Case 'D': return parseInt (objDate-this)/86400000 ); // Calculate the week difference Case 'W': return parseInt (objDate-this)/(86400000*7 )); // Calculate the monthly difference Case 'M': return (objDate. getMonth () + 1) + (objDate. getFullYear ()-this. getFullYear () * 12)-(this. getMonth () + 1 ); // Calculate the year difference Case 'y': return objDate. getFullYear ()-this. getFullYear (); // Input error Default: return undefined; } }; // Check whether it is empty Object. prototype. IsNullOrEmpty = function (){ Var obj = this; Var flag = false; If (obj = null | obj = undefined | typeof (obj) = 'undefined' | obj = ''){ Flag = true; } Else if (typeof (obj) = 'string '){ Obj = obj. trim (); If (obj = '') {// null Flag = true; } Else {// not empty Obj = obj. toUpperCase (); If (obj = 'null' | obj = 'undefined' | obj = '{}'){ Flag = true; } } } Else { Flag = false; } Return flag; |