js获取url的参数和值的N种有效方法
程序员文章站
2024-02-19 15:35:34
...
js获取url的参数和值的N种有效方法
function getParameterByName(name)
{
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" name "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.search);
if(results == null)
return "";
else
return decodeURIComponent(results[1].replace(/\ /g, " "));
}
function getParameterByName(name) {
var match = RegExp('[?&]' name '=([^&]*)')
.exec(window.location.search);
return match && decodeURIComponent(match[1].replace(/\ /g, ' '));
}
var qs = (function(a) {
if (a == "") return {};
var b = {};
for (var i = 0; i < a.length; i)
{
var p=a[i].split('=');
if (p.length != 2) continue;
b[p[0]] = decodeURIComponent(p[1].replace(/\ /g, " "));
}
return b;
})(window.location.search.substr(1).split('&'));
$.urlParam = function(name){
var results = new RegExp('[\\?&]' name '=([^&#]*)').exec(window.location.href);
if (!results)
{
return 0;
}
return results[1] || 0;
}
上一篇: Shell入门知识1——基础认识
下一篇: php判断来源是否是蜘蛛