/** system JS extension function ***///Clear both sides of the space String.prototype.trim = function () {return this.replace (/(^\s*) | ( \s*$)/g, ");};/ /merge multiple blanks for a blank String.prototype.ResetBlank = function () {var regEx =/\s+/g; Return This.replace (RegEx, ');};/ /reserved Number String.prototype.GetNum = function () {var regEx =/[^\d]/g; Return This.replace (RegEx, ');};/ /reserved Chinese String.prototype.GetCN = function () {var regEx =/[^\u4e00-\u9fa5\uf900-\ufa2d]/g; Return This.replace (RegEx, ');};/ /string converted to NumberString.prototype.ToInt = function () {return IsNaN (parseint (this))? This.tostring (): parseint (this); };//gets 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; }};//gets the full file name String.prototype.GetFileName = function () {var regEx =/^.*\/([^\/\?] *).*$/; Return THIS.REplace (regEx, ' $ ');};/ /get file extension String.prototype.GetExtensionName = function () {var regEx =/^.*\/[^\/]* (\.[ ^\.\?] *).*$/; Return This.replace (RegEx, ' $ $ ');};/ Add by Liu Jingning 2010-12-09 *******/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); }};//formatted string add by Liu Jingning 2010-12-09 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 ($, $) {return Args[parseint ($) + 1]; }); Return result;};/ /number complement 0 Number.prototype.LenWithZero = function (ocount) {var strText = this.tostring (); while (Strtext.length < ocount) {StrText = ' 0 ' + StRtext; } return strtext;};/ /Unicode Restore Number.prototype.ChrW = function () {return string.fromcharcode (this);};/ /number array from small to large sort 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;};/ /numeric array from large to small sort 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;};/ /Get the largest item in the array of numbers Array.prototype.GetMax = function () {var ovalue = 0; for (var i = 0; i < this.length; i++) {if (This[i] > Ovalue) {ovalue = this[i]; }} return OValue;};/ /Get the smallest item in a numeric 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;};/ /Gets 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 (' 26085199682010819977222352011620845 '). substr (This.getday () * 5, 5). ToInt (). ChrW (); Return odatetext;};/ /Extend Date format 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,//h "H +": this.gethours (),//Hour "m+": this.getminutes (),//min "S+": This.getseconds (),//sec "q+": Math.floor ((This.getmonth () + 3)/3),//Quarterly "S": this.getmilliseconds ()//msec}; 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 inO) {if (New RegExp ("(" + K +) "). Test (format)) {format = Format.replace (regexp.$1, (regexp.$1.length = = 1)? (O[k]): (("XX" + o[k]). substr (("" + O[k]).)); }} return format;} Date.prototype.Diff = function (interval, objdate) {//If the parameter is insufficient or objdate is not a date type, the callback undefined if (Arguments.length < 2 || Objdate.constructor! = Date) {return undefined;} Switch (interval) {//Calculate seconds Difference case ' s ': return parseint ((Objdate-this)/1000); Calculate differential case ' n ': Return parseint ((objdate-this)/60000); Calculation time difference case ' h ': Return parseint ((objdate-this)/3600000); Calculate the day difference case ' d ': Return parseint ((objdate-this)/86400000); Calculate the week difference case ' W ': Return parseint ((objdate-this)/(86400000 * 7)); Calculate the month difference case ' m ': Return (Objdate.getmonth () + 1) + ((Objdate.getfullyear ()-this.getfullyear ()) *)-(this.GetMonth () + 1); Calculate the year difference case ' y ': return objdate.getfullyear ()-this.getfullyear (); Input error default:return undefined; }};//detection is null 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 = = ") {//is empty flag = true; } else {//is not NULL for obj = Obj.touppercase (); if (obj = = ' NULL ' | | obj = = ' UNDEFINED ' | | obj = = ' {} ') {flag = true; }}}} else {flag = false; } return flag;};
JS Universal Extension Method--turn from the lookout