javascript - How to get the value of flag in search.jsp?flag="+flag in the js of the jump page?
天蓬老师
天蓬老师 2017-05-19 10:13:24
0
1
569

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

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(1)
曾经蜡笔没有小新
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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template