当你的才华还撑不起你的梦想时,你只能一直前进!

打开新页面 自定义方法并获取携带值

 1 // 打开新页面:
 2 window.location.href = "./index.html?id=1"
 3 // 获取携带值:
 4 function GetRequest() {
 5     var url = location.search; //获取url中"?"符后的字串
 6 
 7     var theRequest = new Object();
 8     if (url.indexOf("?") != -1) { //判断是否含有'?'
 9         var str = url.substr(1); //从字符中index为1开始抽取
10         strs = str.split("&"); //字符串分割成字符串数组
11         for (var i = 0; i < strs.length; i++) {
12             theRequest[strs[i].split("=")[0]] = decodeURIComponent(strs[i].split("=")[1]);
13         }
14     }
15     return theRequest;
16 }
17 //  调用
18 var a = GetRequest();
19 var index_id= a['id'];  //console.log---1

 




posted @ 2018-11-20 21:34  One'-_-'Piece  阅读(461)  评论(0编辑  收藏  举报