<a href="" onClick=("1")>修改</a>
function update(id){
window.location.href="role_update.html?id="+id;
}
这样你会发现页面根本没跳转,原因是a标签的href跳转会执行在onClick之前,href里面为空就会刷新,所以解决方法是在href里面添加javascript:;
<a href="javascript:;" onClick=("1")>修改</a>
这样就可以了。
新页面接收参数:
var a=GetRequest();
console.log("id:"+a['id']) //打印出传过来的id
var a=GetRequest();
console.log("id:"+a['id']) //打印出传过来的id
function GetRequest() {
var url = location.search; //获取url中"?"符后的字串
var theRequest = new Object();
if (url.indexOf("?") != -1) {
var str = url.substr(1);
strs = str.split("&");
for (var i = 0; i < strs.length; i++) {
theRequest[strs[i].split("=")[0]] = decodeURIComponent(strs[i].split("=")[1]);
}
}
return theRequest;
}