JS实现页面跳转并传值

第一个页面 page1.html

<html>  

<head>  

    <title>Page 1</title>  

    <script type="text/javascript">  

        function topage2()  

        {  

            var parm1=document.getElementById("tx1").value;  

            var parm2=document.getElementById("tx2").value;  

            var myurl="page2.html"+"?"+"parm1="+parm1+"&parm2="+parm2;  

            window.location.assign(encodeURI(myurl));  

        }  

    </script>  

</head>  

<body>  

  <label id="label1" >page1</label>  

  <br><br>  

  <input type="text" id="tx1" value="text 1">  

  <input type="text" id="tx2" value="text 2">  

  <input type="button" id="bt2" value="go to page2" onclick="topage2()">  

  </body>  

</html>

第二个页面 page2.html

<html>  

<head>  

    <title>Page 2</title>  

    <script type="text/javascript">  

        function getparam1()  

        {  

            var url=location.href;  

            var tmp1=url.split("?")[1];  

            var tmp2=tmp1.split("&")[0];  

            var tmp3=tmp2.split("=")[1];  

            var param1=tmp3;  

            alert(decodeURI(param1));  

        }  

        function getparam2()  

        {  

            var url=location.href;  

            var tmp1=url.split("?")[1];  

            var tmp2=tmp1.split("&")[1];  

            var tmp3=tmp2.split("=")[1];  

            var param2=tmp3;  

            alert(decodeURI(param2));  

        }  

    </script>  

</head>  

<body>  

    <label id="label1" >page2</label>  

    <br><br>  

    <input type="button" id="bt1" value="get parm1" onclick="getparam1()">  

    <br><br>  

    <input type="button" id="bt2" value="get parm2" onclick="getparam2()">  

</body>  

</html>

结果查看:

用浏览器打开page1.html

点击go to page2按纽,进入page2.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值