猿问

如何在跳转页的js中获得search.jsp?flag="+flag 中flag的值?

跳转前的页:
var url = "search.jsp?flag="+flag
window.location.href=url;
如何在search.jsp中js获得flag的值?

<% String flag=request.getParameter("flag"); %>这样alert出来是object HTMLInputElement呢


慕的地6264312
浏览 1201回答 1
1回答

翻阅古今

function getParamName(attr) { //兼容IE9以下浏览器&nbsp; &nbsp; &nbsp; &nbsp; var obj = {};&nbsp; &nbsp; &nbsp; &nbsp; var sesrch = window.location.search;&nbsp; &nbsp; &nbsp; &nbsp; var arr_search = sesrch.split('?')[1];&nbsp; &nbsp; &nbsp; &nbsp; arr_search = arr_search.split('&');&nbsp; &nbsp; &nbsp; &nbsp; for (var i = 0; i < arr_search.length; i++) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var target = arr_search[i].split('=');&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj[target[0]] = target[1];&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; return obj[attr];&nbsp; &nbsp; }&nbsp; &nbsp; //getParamName('flag');&nbsp; &nbsp; function getParamName(attr) { //数组forEach方法实现&nbsp; &nbsp; &nbsp; &nbsp; var obj = {};&nbsp; &nbsp; &nbsp; &nbsp; window.location.search.split('?')[1].split('&').forEach(function(item, index) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj[item.split('=')[0]] = item.split('=')[1];&nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; &nbsp; &nbsp; return obj[attr];&nbsp; &nbsp; }&nbsp; &nbsp; //getParamName('flag');&nbsp; &nbsp; function getParamName(attr) { //数组filter方法实现&nbsp; &nbsp; &nbsp; &nbsp; var obj = {};&nbsp; &nbsp; &nbsp; &nbsp; var newarr = window.location.search.split('?')[1].split('&').filter(function(item, index) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return item.split('=')[0] == attr;&nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; &nbsp; &nbsp; return newarr[0].split('=')[1];&nbsp; &nbsp; }&nbsp; &nbsp; //getParamName('flag');&nbsp; &nbsp; function getParamName(name) {//正则表达式实现&nbsp; &nbsp; &nbsp; &nbsp; var match = RegExp('[?&]' + name + '=([^&]*)')&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .exec(window.location.search);&nbsp; &nbsp; &nbsp; &nbsp; return match && decodeURIComponent(match[1].replace(/\+/g, ' '));&nbsp; &nbsp; };&nbsp; &nbsp; //getParamName('flag');平时自己写的几种方法,仅供参考,我推荐最后正则那个,简单粗暴
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答