js怎么跳转到新页面?
生活随笔
收集整理的這篇文章主要介紹了
js怎么跳转到新页面?
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
方法1:使用location.href
語(yǔ)法:
location.href="URL"
登錄后復(fù)制
示例
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<p>這是<i>location.href</i>方式的示例</p>
<button onclick="myFunc()">點(diǎn)擊這里</button>
<!--重定向到其他網(wǎng)頁(yè)的腳本-->
<script>
function myFunc() {
window.location.href="https://www.php.cn";
}
</script>
</body>
</html>
登錄后復(fù)制
方法2:使用location.replace()
語(yǔ)法:
location.replace("URL")
登錄后復(fù)制
示例:使用location.replace()方法跳轉(zhuǎn)到其他網(wǎng)頁(yè)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<p>這是<i>location.replace()</i>方式的示例</p>
<button onclick="myFunc()">點(diǎn)擊這里</button>
<!--重定向到其他網(wǎng)頁(yè)的腳本-->
<script>
function myFunc() {
location.replace("https://www.php.cn");
}
</script>
</body>
</html>
登錄后復(fù)制
方法3:使用location.assign()
語(yǔ)法:
location.assign("URL")
登錄后復(fù)制
示例:使用location.assign()方法跳轉(zhuǎn)到其他網(wǎng)頁(yè)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<p>這是<i>location.assign()</i>方式的示例</p>
<button onclick="myFunc()">點(diǎn)擊這里</button>
<!--重定向到其他網(wǎng)頁(yè)的腳本-->
<script>
function myFunc() {
location.assign("https://www.php.cn");
}
</script>
</body>
</html>
登錄后復(fù)制
推薦教程:《JavaScript視頻教程》
以上就是js怎么跳轉(zhuǎn)到新頁(yè)面?的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注風(fēng)君子博客其它相關(guān)文章!
總結(jié)
以上是生活随笔為你收集整理的js怎么跳转到新页面?的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: word文字方向怎么变成竖的
- 下一篇: win10如何给磁盘分区