您的位置:首页 > Web前端 > JavaScript

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

2016-12-22 00:00 453 查看
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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: