JS实现页面跳转并传值
2017-07-14 17:38
274 查看
一、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
三、运行结果
用浏览器打开page1.html
![](http://img.blog.csdn.net/20170714173601138?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaGFpc2h1X3poZW5n/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
点击go to page2按纽,进入page2.html
![](http://img.blog.csdn.net/20170714173650177?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaGFpc2h1X3poZW5n/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
点击get parm1或get parm2按纽,显示弹出框
<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
点击get parm1或get parm2按纽,显示弹出框
相关文章推荐
- [HTML]js实现页面跳转,页面A跳到另一个页面B.以及页面传值(中文)
- 页面a跳到另一个页面b,js实现页面跳转传值
- js实现A页面带数据跳转B页面并返回上一层
- html和js实现页面跳转方法
- JS实现页面内跳转的简单代码
- JS实现页面跳转
- js,jquery滚动/跳转页面到指定位置的实现思路
- JS实现页面的跳转
- js实现页面定时跳转
- js实现页面跳转
- js实现页面跳转的几种方式
- js实现页面跳转的几种方式
- js实现页面跳转的几种方式 (转)
- js实现页面刷新和跳转(指定时间)
- js实现页面跳转的几种方式
- button跟submit的区别及使用js实现页面跳转的方式
- Js实现页面跳转的几种方式
- 【转】用JS实现弹出模式对话框,实现页面传值
- js重定向---实现页面跳转的几种方式