Page before jump: var url = "search.jsp?flag=" flagwindow.location.href=url;How to get the value of flag from js in search.jsp?
<% String flag=request.getParameter("flag"); %>The alert will be 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');
Several methods I usually write are for reference only. I recommend the last regular one, which is simple and crude
Several methods I usually write are for reference only. I recommend the last regular one, which is simple and crude