在asp.net處理頁(yè)面間參數(shù)調(diào)用時(shí),Request["param"]是比較常見(jiàn)和方便的方式,那么,js如何獲取request參數(shù)呢?下面介紹兩種方式:
方法1:調(diào)用getQueryString("id") function getQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); var r = window.location.search.substr(1).match(reg); if (r != null) return unescape(r[2]); return null; }
方法2: 調(diào)用 var Request = new Object(); Request = getRequest(); Request["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]]=(strs[i].split("=")[1]); } } return theRequest; }