js跳转到新页面的方法:1、使用location.href="新页面URL"来跳转;2、使用location.replace("新页面URL")来跳转;3、使用location.assign("新页面URL")来跳转。

方法1:使用location.href
语法:
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")示例:使用location.replace()方法跳转到其他网页
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<p>这是<i>location.replace()</i>方式的示例</p>
<div class="aritcle_card">
<a class="aritcle_card_img" href="/xiazai/code/10807">
<img src="https://img.php.cn/upload/webcode/000/000/016/176381100671596.jpg" alt="非常淘 淘宝客源码">
</a>
<div class="aritcle_card_info">
<a href="/xiazai/code/10807">非常淘 淘宝客源码</a>
<p>本源码是我用过最好的淘客站源码。对于新站长很用帮助。重要!!注意上传完程序后要先登陆后台修改域名,否则会跳转到后台已设置的域名。 使用方法1:将文件夹里面的文件上传至您的空间根目录(不要在本地测试,本地测试期间功能将被限制,首页模板显示不正常!)2:访问网址http://您的网址/admin 账号:admin 密码:admin3:填写您基本网站信息,以及重要的淘客相关信息 声明:本程序使用权是本人</p>
<div class="">
<img src="/static/images/card_xiazai.png" alt="非常淘 淘宝客源码">
<span>0</span>
</div>
</div>
<a href="/xiazai/code/10807" class="aritcle_card_btn">
<span>查看详情</span>
<img src="/static/images/cardxiayige-3.png" alt="非常淘 淘宝客源码">
</a>
</div>
<button onclick="myFunc()">点击这里</button>
<!--重定向到其他网页的脚本-->
<script>
function myFunc() {
location.replace("https://www.php.cn");
}
</script>
</body>
</html>
方法3:使用location.assign()
语法:
location.assign("URL")示例:使用location.assign()方法跳转到其他网页
<!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>
推荐教程:《JavaScript视频教程》
以上就是js怎么跳转到新页面?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号