Do not say much nonsense, directly to the code, know what to do with the small partners directly away.
Copy Code code as follows:
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.cookie), 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 String 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;
}
Start 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, failed to create object instance
throw new Error ("Cannot create 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 = = 200) {
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-urlencoded");
}
Http_request.send (parms);
}
};
}();
is not quite good, anyway I am very satisfied.