获取url后的指定参数
用法:?getParam("v");
function getParam(paramName) {
paramValue = "", isFound = !1;
if (this.location.search.indexOf("?") == 0 && this.location.search.indexOf("=") > 1) {
arrSource = unescape(this.location.search).substring(1, this.location.search.length).split("&"), i = 0;
while (i < arrSource.length && !isFound) arrSource[i].indexOf("=") > 0 && arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase() && (paramValue = arrSource[i].split("=")[1], isFound = !0), i++
}
return paramValue == "" && (paramValue = null), paramValue
}
可取中文:
function getUrlParam(key){
// 獲取參數
var url = window.location.search;
// 正則篩選地址欄
var reg = new RegExp("(^|&)"+ key +"=([^&]*)(&|$)");
// 匹配目標參數
var result = url.substr(1).match(reg);
//返回參數值
return result ? decodeURIComponent(result[2]) : null;
}
?
轉載于:https://www.cnblogs.com/Mie929094441/p/7605657.html
總結
以上是生活随笔為你收集整理的获取url后的指定参数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 深入理解计算机系统(2.7)------
- 下一篇: #1413 : Rikka with S