これ以上苦労せずに、コードを提示して、何をすべきかを知っている場合は奪ってください。
コードコピーは次のとおりです。
util = function(){
戻る {
$:function(id){
document.getElementByID(ID)を返します。
}、
トリム:function(str){
return str.replace(/(^/s+)|(/s+$)/g、 "");
}、
レン:function(str){
return str.replace(/[^/x00-/xff]/g、 '**')。
}、
形式:function(str){
var arg = arguments;
return str.replace(// {(/d+)/}/g、function(m、i){
return arg [parseint(i)+1];
});
}、
それぞれ:function(object、callback、args){
var name、i = 0、length = object.length;
if(args){
if(length === undefined){
for(オブジェクトの名前)
if(callback.apply(object [name]、args)=== false)
壊す;
} それ以外
for(; i <length;)
if(callback.apply(object [i ++]、args)=== false)
壊す;
} それ以外 {
if(length === undefined){
for(オブジェクトの名前)
if(callback.call(object [name]、name、object [name])=== false)
壊す;
} それ以外
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();
nextime.sethours(nextime.gethours()+hours);
str = name+"="+escase(value);
if(hours)
str+= "; expires ="+nextipe.togmtstring();
if(パス)
str+= "; path ="+path;
if(domain)
str+= "; domain ="+domain;
document.cookie = str;
}、
getCookie:function(name){
var rs = new regexp( "(^|)"+name+"=([^;]*)(; | $)"、 "gi")。exec(document.cookie)、tmp;
if(tmp = rs)
unescape(TMP [2])を返します。
nullを返します。
}、
delcookie:function(name){
document.cookie = name + "= -1" + "; expires = fri、1999年12月31日23:59:59 gmt;";
}、
/**
*URL文字列
*パームス文字列
*メソッド文字列デフォルト値「GET」
*ASY Boolean Defalut Value True
*成功関数(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;
}
// xmlhttprequestオブジェクトを初期化します
if(window.xmlhttprequest){// mozilla browser
http_request = new xmlhttprequest();
if(http_request.overridemimeType){// mimeカテゴリを設定します
http_request.overridemimeType( "text/xml");
}
} else if(window.activexobject){// ie browser
試す {
http_request = new ActiveXObject( "msxml2.xmlhttp");
} catch(e){
試す {
http_request = new ActiveXObject( "microsoft.xmlhttp");
} catch(e){}
}
}
if(!http_request){//例外、オブジェクトインスタンスの作成に失敗しました
新しいエラー( "xmlhttprequestオブジェクトインスタンスを作成できません。");
nullを返します。
}
http_request.open(method、url、asy);
http_request.onreadystatechange = function(){
if(http_request.readystate == 4){
試す{
if(http_request.status == 200){
config.success(http_request.responsetext);
}
} catch(e){
新しいエラーをスローします( "データ読み取りが失敗しました。");
}
}
};
if(method.tolowercase()== "post"){
http_request.setRequestheader( "content-type"、 "application/x-www-form-urlencoded");
}
http_request.send(parms);
}
};
}();
かなり良いですか?とにかく私はとても満足しています。