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

前端之家收集整理的这篇文章主要介绍了AJAX传参,JS获取当前URL参数(超级实用)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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>111111111</h1>


</body>
</html>

猜你在找的Ajax相关文章