javascript怎么实现页面跳转
时间:2021-04-22
来源:互联网
今天PHP爱好者为您带来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属性跳转到其他网页
语法:
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>
<button onclick="myFunc()">点击这里</button>
<!--重定向到其他网页的脚本-->
<script>
function myFunc() {
location.replace("https://www.php.cn");
}
</script>
</body>
</html>
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>
以上就是javascript怎么实现页面跳转的详细内容,更多请关注php爱好者其它相关文章!
-
永劫无间多少钱一个红 时间:2024-12-20
-
永劫无间多少钱开一个箱子 时间:2024-12-20
-
阿瑞斯病毒2火铳弹药怎么获得?阿瑞斯病毒2火铳弹药获得方法 时间:2024-12-19
-
阿瑞斯病毒2哈士奇在哪?阿瑞斯病毒2哈士奇获得方法 时间:2024-12-19
-
寻道大千反击流阵容推荐 时间:2024-12-19
-
和平精英性别怎么换?和平精英性别转换方法 时间:2024-12-19
今日更新
- thinkphp中如何使用AOP切面编程快速验证我们的数据
阅读:19
- 如何利用PHP来输出一个杨辉三角
阅读:18
- javascript删除数组元素的方法
阅读:18
- 如何在JS中改变DOM元素的文本内容
阅读:18
- laravel查询不再需要写大量if else判断了!
阅读:18
- 如何更加优雅的从HTML中获取DOM元素
阅读:18
- javascript如何把时间戳转换为普通日期格式
阅读:18
- javascript如何判断字符串中是否包含某个字符串
阅读:20
- javascript和java有什么区别
阅读:20
- javascript中对象怎么转换为字符串
阅读:20