//获取url中的参数
function getUrlParam(name) {
var url = document.location.toString(); // url ='http://yde.com/school-xq.html?post_id=656&name=taofei&age=25';(测试链接)
var arrObj = url.split("?");
if (arrObj.length > 1) {
var arrPara = arrObj[1].split("&");
var arr;
for (var i = 0; i < arrPara.length; i++) {
arr = arrPara[i].split("=");
if (arr != null && arr[0] == name) {
return arr[1];
}
}
return "";
}
else {
return "";
}
};
//接收URL中的参数
var id = getUrlParam('post_id'); // id=65
var name = getUrlParam('name'); // name=taofei
这样就能获取到url的参数了