js怎么跳转到新页面?
互联网
20-7-18
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> <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怎么跳转到新页面?的详细内容,更多内容请关注技术你好其它相关文章!
免责声明:
1.资讯内容不构成投资建议,投资者应独立决策并自行承担风险
2.本文版权归属原作所有,仅代表作者本人观点,不代表本站的观点或立场
1.资讯内容不构成投资建议,投资者应独立决策并自行承担风险
2.本文版权归属原作所有,仅代表作者本人观点,不代表本站的观点或立场