跳轉前的頁:var url = "search.jsp?flag=" flagwindow.location.href=url;如何在search.jsp中js取得flag的值?
<% String flag=request.getParameter("flag"); %>這樣alert出來是object HTMLInputElement呢
欢迎选择我的课程,让我们一起见证您的进步~~
function getParamName(attr) { //兼容IE9以下浏览器 var obj = {}; var sesrch = window.location.search; var arr_search = sesrch.split('?')[1]; arr_search = arr_search.split('&'); for (var i = 0; i < arr_search.length; i++) { var target = arr_search[i].split('='); obj[target[0]] = target[1]; } return obj[attr]; } //getParamName('flag'); function getParamName(attr) { //数组forEach方法实现 var obj = {}; window.location.search.split('?')[1].split('&').forEach(function(item, index) { obj[item.split('=')[0]] = item.split('=')[1]; }); return obj[attr]; } //getParamName('flag'); function getParamName(attr) { //数组filter方法实现 var obj = {}; var newarr = window.location.search.split('?')[1].split('&').filter(function(item, index) { return item.split('=')[0] == attr; }); return newarr[0].split('=')[1]; } //getParamName('flag'); function getParamName(name) {//正则表达式实现 var match = RegExp('[?&]' + name + '=([^&]*)') .exec(window.location.search); return match && decodeURIComponent(match[1].replace(/\+/g, ' ')); }; //getParamName('flag');
平常自己寫的幾種方法,僅供參考,我推薦最後正則那個,簡單粗暴
平常自己寫的幾種方法,僅供參考,我推薦最後正則那個,簡單粗暴