var h = {}; H.get = function (URL, data, OK, error) {$.ajax ({url:url, data:data, DataType: ' JSON ', Success:ok, error:error}); } h.post = function (URL, data, OK, error) {$.ajax ({url:url, data:data, type: ' Post ', DataType: ' json ', Success:ok, error:error}); }//Get URL parameter h.url = function (URL) {if (!url) {url = location.search.substring (1); } else {url = url.substr (Url.indexof ('? ') + 1); } var args = new Object (); Declare and initialize a "class"//Get Address (URL) "?" The string that follows. var query = decodeURI (URL); var pairs = Query.split ("&"); Split URL (Don't forget ' & ' is used to connect the next parameter) for (var i = 0; i < pairs.length; i++) {var pos = pairs[i].indexof (' = '); if (pos = =-1) continue; It is looking for an array with an equal sign [i] var argname = pairs[i].substring (0, POS); Parameter name var value = pairs[i].substring (pos + 1); //The parameter value//is stored in the "args" object in the form of a key-value pair Args[argname] = decodeURI (value); } return args; }//returns the actual length of the string, a Chinese character is counted 2 lengths String.prototype.strlen = function () {return this.replace (/[^\x00-\xff]/g, "* *"). L Ength; }//String out of ellipsis String.prototype.cutstr = function (len) {var restr = this; var wlength = This.replace (/[^\x00-\xff]/g, "* *"). Length; if (Wlength > Len) {for (var k = len/2; k < this.length; k++) {if (This.substr (0, k). Repla CE (/[^\x00-\xff]/g, "* *"). Length >= len) {restr = This.substr (0, K) + "..."; Break }}} return restr; }//Replace All String.prototype.replaceAll = function (S1, S2) {return this.replace (new RegExp (S1, "GM"), S2)}//String to go Space String.prototype.trim = function () {return this.replace (/(^\s*) | ( \s*$)/g, ""); } String.prototype.trimAll = function () {return this.replace (/\s+/g, ""); } String.prototype.lTrim = function () {return this.replace (/(^\s*)/g, ""); } String.prototype.rTrim = function () {return this.replace (/(\s*$)/g, ""); }//Determine whether to start with a string String.prototype.startWith = function (s) {return This.indexof (s) = = 0}//Determine whether to end string with a string . Prototype.endwith = function (s) {var d = this.length-s.length; return (d >= 0 && this.lastindexof (s) = = d)}//delete duplicate elements in array function Getunique (somearray) {Temparr ay = somearray.slice (0); Copy array to temporary array for (var i = 0; i < temparray.length; i++) {for (var j = i + 1; j < Temparray.length;) {if (temparray[j] = = Temparray[i])//After elements are deleted and counted if they are the same as to be compared, the following elements are automatically Before, so the pointer J does not move {Temparray.splice (j, 1); } else {j + +; }//Different, the pointer moves}} return temparray; }//Determine if there are duplicate elements in the array function confirmrepeat (Somearray) {Temparray = Somearray.slice (0); Copy array to temporary array for (var i = 0; i < temparray.length; i++) {for (var j = i + 1; j < Temparray.length;) {if (temparray[j] = = Temparray[i])//After elements are deleted and counted if they are the same as to be compared, the following elements are automatically Before, so the pointer J does not move {return true; } else {j + +; }//Different, the pointer moves}} return false; }//Determine if a value is in the array Array.prototype.in_array = function (e) {for (i = 0; i < this.length; i++) {if (th Is[i] = = e) return true; } return false; }//Determine the position of a value in the array Array.prototype.indexOf = function (e) {for (i = 0; i < this.length; i++) {if (this[ I] = = e) return i; } return-1; }//Escape HTML tag function HtmlEncode (text) {return text.replace (/&/g, ' & '). Replace (/\ "/g, '" '). Replace (/< ;/g, ' < '). Replace (/>/g, ' > ')}//FormatDate DateFormat (' Yyyy_mm_dd Hh:mm:ss:SS week w q quarter ') function DateFormat (format, date) {if (!date) {date = n EW Date (); } var Week = [' Day ', ' one ', ' two ', ' three ', ' four ', ' five ', ' six ']; var o = {"y+": Date.getyear (),//year "m+": Date.getmonth () + 1,//month "d+": Date.getdate () ,//day "H +": date.gethours (),//hour "H +": date.gethours (),//hour "m+": date.getminutes (), Minute "s+": Date.getseconds (),//second "q+": Math.floor ((Date.getmonth () + 3)/3),//quarter "S": Date.getmilliseconds (),//millisecond "W": Week[date.getday ()]} if (/(y+)/.test (format)) { Format = Format.replace (regexp.$1, (date.getfullyear () + ""). substr (4-regexp.$1.length)); } for (var k in O) {if (New RegExp ("(" + K + ")"). Test (format)) {format = Format.replace (rege xp.$1, Regexp.$1.length = = 1? O[k]: ("XX" + o[k]). substr (("" + o[k]). length); }} return format; }//Set cookie value function Setcookie (name, value, Hours) {var d = new Date (); var offset = 8; var UTC = D.gettime () + (D.gettimezoneoffset () * 60000); var nd = UTC + (3600000 * offset); var exp = new Date (ND); Exp.settime (Exp.gettime () + Hours * 60 * 60 * 1000); Document.cookie = name + "=" + Escape (value) + ";p ath=/;expires=" + exp.togmtstring () + ";d omain=360doc.com;"} Get cookie Value function GetCookie (name) {var arr = Document.cookie.match (new RegExp (^|) + name + "= ([^;] *)(;|$)")); if (arr! = null) return unescape (arr[2]); return NULL}//Add Favorite function Addfavorite (sURL, stitle) {try {window.external.addFavorite (sURL, Stit Le)} catch (e) {try {Window.sidebar.addPanel (stitle, sURL, "")} catch (e) { Alert ("Bookmark failed, add with Ctrl+d")}}}//Set homepage function sethomepage (homeurl) {if (document.all) { document.body.style.behavior = ' url (#default #homepage) '; Document.body.setHomePage (Homeurl)} else if (Window.sidebar) {if (Window.netscape) {try { Netscape.security.PrivilegeManager.enablePrivilege ("Universalxpconnect")} catch (e) { Alert ("The action is rejected by the browser, if you want to enable the feature, enter About:config in the Address bar, and then set the item Signed.applets.codebase_principal_support value to True"); }} var prefs = components.classes[' @mozilla. Org/preferences-service;1 '].getservice (components.in Terfaces.nsiprefbranch); Prefs.setcharpref (' Browser.startup.homepage ', Homeurl)}}//cross-browser binding event function Addeventsamp (obj, evt, fn) { if (!otarget) {return;} if (Obj.addeventlistener) {Obj.addeventlistener (evt, FN, false); } else if (obj.attachevent) {obj.attachevent (' on ' + evt, FN); } else {otarget["on" + sevttype] = fn; }}//cross-Browser Delete event function delevt (obj, evt, fn{if (!obj) {return;} if (Obj.addeventlistener) {Obj.addeventlistener (evt, FN, false); } else if (otarget.attachevent) {obj.attachevent ("on" + evt, FN); } else {obj["on" + evt] = fn; }}//Determine if mobile device access function ismobileuseragent () {return (/iphone|ipod|android.*mobile|windows.*phone|blackberry. *mobile/i.test (Window.navigator.userAgent.toLowerCase ())); }//Perfect judgment is URL function isurl (strurl) {var regular =/^\b ((https?| FTP): \/\/)? [-a-z0-9]+ (\.[ -a-z0-9]+) *\. (?: com|edu|gov|int|mil|net|org|biz|info|name|museum|asia|coop|aero| [A-z] [a-z]| ((25[0-5]) | (2[0-4]\d) | (1\d\d) | ([1-9]\d) |\d)) \b (\/[-a-z0-9_:\@&?=+,.! \/~%\$]*)?) $/i if (regular.test (strURL)) {return true; } else {return false; }}//Get page height function getpageheight () {var g = document, A = G.body, F = g.documentelement, d = G.compatmode = = "Backcompat"? A:g.documentelement; Return Math.max (F.scrollheight,A.scrollheight, D.clientheight); }//Get page width function getpagewidth () {var g = document, A = G.body, F = g.documentelement, d = G.compatmode = = "Back Compat "? A:g.documentelement; Return Math.max (F.scrollwidth, A.scrollwidth, d.clientwidth); }//Get page visual width function getpageviewwidth () {var d = document, a = D.compatmode = = "Backcompat" ? D.body:d.documentelement; return a.clientwidth; }//Get page visual height function getpageviewheight () {var d = document, a = D.compatmode = = "Backcompat" ? D.body:d.documentelement; return a.clientheight; }//Get page ScrollLeft function Getpagescrollleft () {var a = document; return A.documentelement.scrollleft | | A.body.scrollleft; }//Get page scrolltop function getpagescrolltop () {var a = document; return A.documentelement.scrolltop | | A.body.scrolltop; }//Get the form visible range of wide and high function getviewsize () {var de = docUment.documentelement; var db = document.body; var vieww = De.clientwidth = = 0? Db.clientWidth:de.clientWidth; var VIEWH = De.clientheight = = 0? Db.clientHeight:de.clientHeight; Return Array (VIEWW, VIEWH); }//random number timestamp function uniqueId () {var a = Math.random, B = parseint; Return number (new Date ()). ToString () + B (Ten * A ()) + B (Ten * A ()) + B (Ten * A ()); }//Get the location where the page is being rolled away function Getscrollxy () {return document.body.scrollTop? {x:document.body.scrollleft, y:document.body.scrolltop}: {X:document.documentelemen T.scrollleft, Y:document.documentelement.scrolltop}}//Match domestic phone number (0511-4405222 or 021-87888822) funct Ion Istell (str) {var result = Str.match (/\d{3}-\d{8}|\d{4}-\d{7}/); if (result = = null) return false; return true; }//Match ID (15-bit or 18-bit) function Isidcard (str) {var result = Str.match (/\d{15}|\d{18}/); if (result = = null) return false; Return TruE }//Mobile phone function checkmobile (str) {if (! ( /^1[3|5|8][0-9]\d{4,8}$/.test (str)) {return false; } return true; }//Determine if the input is a string function Isalphanumber (str) {var result = Str.match (/^[a-za-z0-9]+$/) consisting of a 0-9/A-z/A-Z; if (result = = null) return false; return true; }//Determine if the input is a valid e-mail function isemail (str) {var result = Str.match (/^\w+ (-\w+) | ( \.\w+)) *\@[a-za-z0-9]+ ((\.| -) [a-za-z0-9]+] *\. [a-za-z0-9]+$/]; if (result = = null) return false; return true; }//Amount uppercase conversion function transform (' 123431233132.23 ') functions transform (Tranvalue) {try {var i = 1; var dw2 = new Array ("", "Million", "billion"); Large unit var dw1 = new Array ("Pick", "Bai", "thousand"); Small unit var dw = new Array ("0", "one", "II", "three", "Restaurant", "WU", "Lu", "Qi", "ba", "JIU"); Integer part with//the following is lowercase converted to uppercase displayed in the Total Uppercase text box//separate integer with decimal var Source = splits (Tranvalue); var num = source[0]; var dig = source[1]; converting integerspartial var k1 = 0; Count small unit var k2 = 0; Count Large unit var sum = 0; var str = ""; var len = source[0].length; The length of the integer for (i = 1; I <= len; i++) {var n = source[0].charat (len-i);//Get a number on a single digit var bn = 0; if (len-i-1 >= 0) {bn = Source[0].charat (Len-i-1);//Get the number of a single digit before the first digit} sum = sum + number (n); if (sum! = 0) {str = Dw[number (n)].concat (str);//Get the uppercase number corresponding to the number and insert it in front of the STR string if (n = = ' 0 ') sum = 0; if (len-i-1 >= 0) {//within the number range if (k1! = 3) {//Plus small unit if (bn! = 0 ) {str = dw1[k1].concat (str); } k1++; } else {//Do not add small units, increase unit K1 = 0; var temp = Str.charat (0); if (temp = = "Million" | | temp = = "billion")//if large unit beforeNo number is shed to large units str = STR.SUBSTR (1, str.length-1); str = dw2[k2].concat (str); sum = 0; }} if (K1 = = 3) {//small units to thousands of large units into a k2++; }}//Convert decimal part var strdig = ""; if (Dig! = "") {var n = dig.charat (0); if (n! = 0) {Strdig + = Dw[number (n)] + "Corner";//Plus number} var n = dig.charat (1); if (n! = 0) {Strdig + = Dw[number (n)] + "sub";//Plus number}} str + = " Yuan "+ strdig; } catch (e) {return "$ 0"; } return str; }//split integer with decimal function splits (tranvalue) {var value = new Array (', '); temp = Tranvalue.split ("."); for (var i = 0; i < temp.length; i++) {value = temp; } return value; }//formatted digital function Number_format (number, decimals, Dec_point, thousANDS_SEP) {/* * parameter Description: * Number: Numbers to format * Decimals: Keep several decimals * dec_point: Decimal symbol * THOUSANDS_SEP: thousand-bit symbol * */Number = (number + "). Replace (/[^0-9+-ee.) /g, "); var n =!isfinite (+number)? 0: +number, prec =!isfinite (+decimals)? 0:math.abs (decimals), Sep = (typeof thousands_sep = = = ' undefined ')? ', ': thousands_sep, Dec = (typeof dec_point = = = ' undefined ')? '. ': dec_point, S = ', Tofixedfix = function (n, prec) {var k = Math.pow (ten, PREC); Return ' + Math.ceil (n * k)/k; }; s = (prec? tofixedfix (N, prec): ' + Math.Round (n)). Split ('. '); var re =/(-?\d+) (\d{3})/; while (Re.test (s[0))) {S[0] = S[0].replace (Re, "$" + Sep + "$ $"); } if ((S[1] | | | "). Length < Prec) {s[1] = S[1] | | ‘‘; S[1] + = new Array (prec-s[1].length + 1). Join (' 0 '); } return S.join (DEC); }
Common JS method to organize