加入收藏 | 设为首页 | 会员中心 | 我要投稿 驾考网 (https://www.jiakaowang.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 教程 > 正文

JS上获取URL中的参数数据

发布时间:2023-08-15 14:32:55 所属栏目:教程 来源:
导读:代码如下:

function getParam(paramName) {

paramValue = "";

isFound = false;

if (this.location.search.indexOf("?") == 0 && this.location.search.indexOf("=") > 1) {

代码如下:
 
function getParam(paramName) {
 
    paramValue = "";
 
    isFound = false;
 
    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) {
 
            if (arrSource[i].indexOf("=") > 0) {
 
                if (arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase()) {
 
                    paramValue = arrSource[i].split("=")[1];
 
                    isFound = true;
 
                }
 
            }
 
            i++;
 
        }
 
    }
 
    return paramValue;
 
}
 
如://www.Cuoxin.com/UserQuery.aspx?id=202
 
getParam("id")为202
 
 

(编辑:驾考网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章