[HTML]js实现页⾯跳转,页⾯A跳到另⼀个页⾯B.以及页⾯传值
(中⽂)
要实现从⼀个页⾯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.back(-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>
页⾯传值:
第⼀个页⾯:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>⽆标题⽂档</title>
</head>
<SCRIPT LANGUAGE="JavaScript">
function test(){
var s = ElementById("txt");
location.href="test2.html?"+"txt="+encodeURI(s.value);
}
</SCRIPT>
<body>
<input type="text" id="txt">
</br>
<input type="button" value="TEST" onclick="test()"/>
</body>
pdf转html</html>
第⼆个页⾯:(test2.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 id = decodeURI(loc.substr(n2+1, n1-n2));//从=号后⾯的内容
alert(id);
//document.write(id)
</script>
</body>
</html>
注:中⽂传输:可以在页⾯a⽤encodeURI 编码url 在b页⾯⽤decodeURI解码url
发布评论