js页面跳转方法:1、使用“location.href="url"”;2、使用“location.replace("url")”;3、使用“location.assign("url")”;4、使用“window.open("url")”。

本教程操作环境:windows7系统、javascript1.8.5版、Dell G3电脑。
javascript实现页面跳转的方法:
1、使用location.href属性跳转到其他网页
语法:
立即学习“Java免费学习笔记(深入)”;
location.href="URL";
示例:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<p>这是<i>location.href</i>方式的示例</p>
<button onclick="myFunc()">点击这里</button>
<!--重定向到其他网页的脚本-->
<script>
function myFunc() {
window.location.href="https://www.php.cn";
}
</script>
</body>
</html>2、使用location.replace()方法跳转到其他网页
语法:
location.replace("URL");示例:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<p>这是<i>location.replace()</i>方式的示例</p><div class="aritcle_card flexRow">
<div class="artcardd flexRow">
<a class="aritcle_card_img" href="/ai/2209" title="PhotoG"><img
src="https://img.php.cn/upload/ai_manual/000/000/000/175680099936492.png" alt="PhotoG" onerror="this.onerror='';this.src='/static/lhimages/moren/morentu.png'" ></a>
<div class="aritcle_card_info flexColumn">
<a href="/ai/2209" title="PhotoG">PhotoG</a>
<p>PhotoG是全球首个内容营销端对端智能体</p>
</div>
<a href="/ai/2209" title="PhotoG" class="aritcle_card_btn flexRow flexcenter"><b></b><span>下载</span> </a>
</div>
</div>
<button onclick="myFunc()">点击这里</button>
<!--重定向到其他网页的脚本-->
<script>
function myFunc() {
location.replace("https://www.php.cn");
}
</script>
</body>
</html>【推荐学习:javascript高级教程】
3、使用location.assign()方法跳转到其他网页
语法:
location.assign("URL")示例:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<p>这是<i>location.assign()</i>方式的示例</p>
<button onclick="myFunc()">点击这里</button>
<!--重定向到其他网页的脚本-->
<script>
function myFunc() {
location.assign("https://www.php.cn");
}
</script>
</body>
</html>4、使用window.open()方法跳转到其他网页
语法:
window.open("URL");示例:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<p>这是<i>window.open()</i>方式的示例</p>
<button onclick="myFunc()">点击这里</button>
<!--重定向到其他网页的脚本-->
<script>
function myFunc() {
window.open("https://www.php.cn");
}
</script>
</body>
</html>更多编程相关知识,请访问:编程视频!!










