要实现从一个页面A跳到另一个页面B,js实现就在A的js代码加跳转代码
JS跳转大概有以下几种方式:
第一种:(跳转到b.html)
<script language="javascript" type="text/javascript">
window.location.href="b.html";
</script>
第二种:(返回上一页面)
<script language="javascript">
window.history.go(-1);
</script>
第三种:
<script language="javascript">
window.navigate("b.html");
</script>
第四种:
<script language="JavaScript">
self.location=’b.html’;
</script>
第五种:
<script language="javascript">
top.location=’b.html’;
</script>
页面传值:
第一个也页面
1 <head> 2 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 3 <title>无标题文档</title> 4 </head> 5 <SCRIPT LANGUAGE="JavaScript"> 6 function test(){ 7 var s = document.getElementById("txt"); 8 location.href="test2.html?"+"txt="+encodeURI(s.value); 9 } 10 </SCRIPT> 11 <body> 12 13 <input type="text" id="txt"> 14 </br> 15 <input type="button" value="TEST" onclick="test()"/> 16 17 </body> 18 </html>
页面传值:
第二个页面
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <body> <script language="javascript" type="text/javascript"> var loc = location.href; var n1 = loc.length;//地址的总长度 var n2 = loc.indexOf("=");//取得=号的位置 var id = decodeURI(loc.substr(n2+1, n1-n2));//从=号后面的内容 alert(id); //document.write(id) </script> </body> </html>
----------------------------------------转自https://www.cnblogs.com/lyggqm/p/5688028.html