前端页面传参两种常用方法

//本地存储:
window.localStorage.removeItem("transactionID")
window.localStorage.setItem("transactionID",transactionID)
window.localStorage.getItem("transactionID");
sessionStorage//会话级别的 关闭窗口 就不见了 所以 可以将transactionID进行sessionStorage存储;
//url传值:
function GetRequest() {
        var url = location.search; //获取url中"?"符后的字串   window.location.href="test.html?name="+name+"&password="+password
        var theRequest = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            strs = str.split("&");
            for(var i = 0; i < strs.length; i ++) {
                theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
            }
        }
        return theRequest;
    }
    var theRequest= GetRequest()
    var name=theRequest.name; //Request["username"]也可以
    var password=theRequest.password Request["password"]也可以
    alert(name+";"+password)

当然还有很多,如open,Cookie等;

//为了安全起见,建议后端存储。

猜你喜欢

转载自blog.csdn.net/Chou_Junn/article/details/81532140