Html跳转页面时,URL传值-获取

版权声明:本文为博主原创文章,未经博主允许不可转载。转载请注明出处 https://blog.csdn.net/qq_32442967/article/details/82798859

页面 a.html 跳转页面 b.html , a.html 传值到 b.html

页面a.html

 <body>
	<input type="button" onclick="window.location.href='a.html?tj_type=2'" value="传值"/>
 </body>

页面b.html 中的js方法

<script>
	var tj_type= getParams("tj_type");
    console.log(tj_type);
    
    //获取传过来的值
    function getParams(key) {
        var reg = new RegExp("(^|&)" + key + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) {
            return unescape(r[2]);
        }
        return null;
    };
	
</script>

https://www.foryh.com/

猜你喜欢

转载自blog.csdn.net/qq_32442967/article/details/82798859