search

Home  >  Q&A  >  body text

javascript - How to get the value of flag in search.jsp?flag="+flag in the js of the jump page?

Page before jump:
var url = "search.jsp?flag=" flag
window.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

天蓬老师天蓬老师2804 days ago606

reply all(1)I'll reply

  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-19 10:15:24

    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

    reply
    0
  • Cancelreply