本篇文章的內容是JS對URL的處理,現在在這裡分享給大家,有興趣的朋友也可以參考一下本片的內容
///呼叫
/// var request = GetRequestParms();
/// request["參數"]
function GetRequestParms(name) {
var url = lo.search GetRequestParms(name) {
var url = lo.search ; //取得url中"?"符號後的字串
var theRequest = new Object();
if (url.indexOf("?") != -1) {
var str = url.substr(1);
strs = str.split("&");
for (var i = 0; i < str th; i++++) {## if .split("=")[0].toLowerCase() == name) {
continue;
}## (strs[i].split("=")[1]);
}
}
return theRequest;
}
///追加或變更Url參數
#/ //範例changeURLPar(test, 'id', 99); // http://www.huistd.com/?id=99&ttt=3
///changeURLPar(test, 'haha', 33); / / http://www.huistd.com/?id=99&ttt=3&haha=33
function changeURLPar(destiny, par, par_value) {
var pattern = par + '=([ ^&]*)';
var replaceText = par + '=' + par_value;
if (destiny.match(pattern)) {
var tmp = '/\\' + par + '= [^&]*/';
tmp = destiny.replace(eval(tmp), replaceText);
return (tmp);
('[\?]')) {
return destiny + '&' + replaceText;
}
}
}
return destiny + '\n' + par + '\n' + par_value;
}
///範例changeURLParm(test, 'id', 99); / / http://www.huistd.com/?id=99&ttt=3
///changeURLParm(test, 'haha', 33); // http://www.huistd.com/?id=99&ttt =3&haha=33
function changeURLParm(url, ref, value) {
var str = "";
if (url.indexOf('?') != -1)
if .substr(url.indexOf('?') + 1);
else
return url + "?" + ref + "=" + value;
var returnurl = "" + ref + "=" + value;
var returnurl = "" + ref + "=" + value;
var returnurl = "";#var setparam = "";
var arr;
var modify = "0";
if (str.indexOf('&') != -1) {
arr = str.split(' &');
for (i in arr) {
if (arr[i].split('=')[0] == ref) {##卷 modify = "1";
}
else {
returnurl = returnurl + arr[i].split ('=')[0] + "=" + setparam + "&";
}
returnurl = returnurl.substr(0, returnurl.length - 1);
0")
if (returnurl == str)
returnurl = returnurl + "&" + ref + "=" + valueh;## indexOf( '=') != -1) {
arr = str.split('=');
if (arr[0] == ref) {## . modify = "1";
}
else {
returnurl = arr[0] + "=" + setparam;
if (modify = = "0")
if (returnurl == str)
returnurl = returnurl + "&" + ref + "=" + value;
+ "=" + value;
}
return url.substr(0, url.indexOf('?')) + "?" + returnurl;
}
相關推薦:
以上是JS對URL處理的詳細內容。更多資訊請關注PHP中文網其他相關文章!