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

AJAX传参,JS获取当前URL参数(超级实用)

发布时间:2020-12-16 03:34:17 所属栏目:百科 来源:网络整理
导读:t.html !DOCTYPE htmlhtmlheadmeta charset="UTF-8"titleInsert title here/titlescript type="text/javascript"var getParam = function(name){ var search = document.location.search; var pattern = new RegExp("[?]"+name+"=([^]+)","g"); var matcher

t.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>

<script type="text/javascript">

var getParam = function(name){
    var search = document.location.search;
    var pattern = new RegExp("[?&]"+name+"=([^&]+)","g");
    var matcher = pattern.exec(search);
    var items = null;
    if(null != matcher){
            try{
                    items = decodeURIComponent(decodeURIComponent(matcher[1]));
            }catch(e){
                    try{
                            items = decodeURIComponent(matcher[1]);
                    }catch(e){
                            items = matcher[1];
                    }
            }
    }
    return items;
};

window.onload=function(){
	alert(getParam('ids'));
	alert(getParam('cid'));
}
</script>
</head>
<body>

<h1>222221111</h1>


</body>
</html>

(编辑:李大同)

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

    推荐文章
      热点阅读