Util=function () {return {$:function (ID) {return document.getElementById (ID); }, Trim:function (str) {return str.replace (/(^\s+) | ( \s+$)/g, ""); }, Len:function (str) {return str.replace (/[^\x00-\xff]/g, ' * * '). length; }, Format:function (str) {var arg = arguments; Return Str.replace (/\{(\d+) \}/g, function (M, i) {return arg[parseint (i) +1]; }); }, Each:function (object, callback, args) {var name, i = 0, length = object.length; if (args) {if (length = = = undefined) {for (name in object) if (callback.apply (object[name], args) = = = False) break; } else for (; i < length;) if (callback.apply (object[i++], args) = = = False) break; } else {if (length = = undefined) {for (name in object) if (Callback.call (object[name], name, object[name]) = = = False) break; } else for (var value = object[0]; I < length && Callback.call (value, I, value)!== false; Value = Object[++i]) {}}}, Setcookie:function (name,value,hours,path,domain) {var str =new String (); var nexttime=new Date (); Nexttime.sethours (Nexttime.gethours () +hours); str=name+ "=" +escape (value); if (hours) str+= "; expires=" +nexttime.togmtstring (); if (path) str+= ";p ath=" +path; if (domain) str+= ";d omain=" +domain; DOCUMENT.COOKIE=STR; }, Getcookie:function (name) {var rs=new RegExp ("(^|)" +name+ "= ([^;] *) (; |$) "," GI "). EXEC (document. Cookies), TMP; if (TMP=RS) return unescape (tmp[2]); return null; }, Delcookie:function (name) {Document.cookie = name + "=-1" + "; Expires=fri, Dec 1999 23:59:59 GMT; ";},/** *url string *parms string *method Strin G Default Value "Get" *asy Boolean Defalut value True *success Function (http_request.responsetext) * * /ajax:function (config) {var url=config.url, parms= (config.parms?config.parms: "") + "& ; t= "+new Date (). GetTime (), method=config.method| |" Get ", asy=true; var http_request=null; if (method.tolowercase () = = "Get") {url=url+ "?" +parms; Parms=null; }//Begins initializing the XMLHttpRequest object if (window. XMLHttpRequest) {//mozilla browser http_request = new XMLHttpRequest (); if (http_request.overridemimetype) {//Set MIME category Http_request.overridemimetype ("Text/xml"); }} else if (window. ActiveXObject) {//IE browser try {http_request = new ActiveXObject ("Msxml2.xmlhttp"); } catch (e) {try {http_request = new ActiveXObject ("Microsoft.XMLHTTP"); } catch (E) {}}} if (!http_request) {///exception, create object instance failed throw new Error ( "Cannot create an XMLHttpRequest object instance."); return null; } http_request.open (Method,url,asy); Http_request.onreadystatechange=function () {if (http_request.readystate = = 4) {try{ if (Http_request.status = =) {config.success (http_request.responsetext); }}catch (e) {throw new Error ("Data read failed."); } } }; if (method.tolowercase () = = "Post") {Http_request.setrequestheader ("Content-type", "Application/x-www-form-url Encoded "); } http_request.send (parms); } };} ();
JavaScript several common static methods