標籤:rgs pos 根據 cat spl mat member null UNC
1.方法一:js的Regex:請求路徑:http://127.0.0.1/pec/jsp/member/refundOrder.jsp?status=4
<script> var status= getUrlAttribute(‘status‘); if(null!=status) { alert(status); } function getUrlParam(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if(r != null) { return unescape(r[2]); } return null; }</script>
2.方二:
function getUrlParam(parameName){ //location.search是從當前URL的?號開始的字串,即查詢字串 var query = (location.search.length > 0 ? location.search.substring(1) : null); if(null!=query) { var args = new Object( ); var pairs = query.split("&"); for(var i = 0; i < pairs.length; i++) { var pos = pairs[i].indexOf("="); if (pos == -1) continue; var argname = pairs[i].substring(0,pos); var value = pairs[i].substring(pos+1); value = decodeURIComponent(value); args[argname] = value; } //根據鍵名擷取值 return args[parameName]; } return null;}
根據url的屬性名稱來取屬性值賦值給js