JS代码怎么跳转到另一个页面呢

JavaScript016

JS代码怎么跳转到另一个页面呢,第1张

要实现从一个页面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>

举个例子:

<html>

<body><input type="button" value="跳转到详细页" onclick="jump()"></body>

</html>

js:

function jump()

{

window.location.href="是跳转的地址"

}

定义和用法

<a>标签定义超链接,用于从一张页面链接到另一张页面。

<a>元素最重要的属性是 href 属性,它指示链接的目标。