推薦使用此方式: url連接爲:newsDetail.html?id=8a8080e35f90d9fd015f90dac7750001&modelId=123456 var URLParams = new Array(); var params = document.location.search.substr(1).split('&'); for (i=0; i < params.length ; i++){ var aParam = params[i].split('='); URLParams[aParam[0]] = aParam[1]; } var nodeId=URLParams["id"]; //節點的id var modelId=URLParams["modelId"]; //模型的modelId
方式二:
此方式不推薦,匹配不必定完美,好比一些特殊字符
url連接爲:http://127.0.0.1:8080/opera/index.html?token=OGE4MDgwZTM1ZjhmODQ1ODAxNWY4Zjg0NThhODAwMDA~
var url = location.search;
var reg = /([^\=\?|\&]+)\=([^\=\&\#]+)/g;
var parameters = url.match(reg);
var token = null;
url.replace(reg,function($1,$2,$3){
// 獲取token
token = $3;
});
方式二:詳細例子 var url = "www.zhangyunling.com?aada=adaa&adad=adasd&sdfs=asdad#did", reg = /([^\=\?|\&]+)\=([^\=\&\#]+)/g; var aa = url.match(reg); console.log(url); console.log(aa); url.replace(reg,function($1,$2,$3){ console.log($2+"="+$3); });