方法
window.location.href = "要跳转的URL";
或
window.location = "要跳转的URL";
或
location = "要跳转的URL";
示例
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>给按钮添加跳转功能【类似a标签】</title> <script type="text/javascript"> window.onload = function(){ document.getElementById("btn").onclick = function(){ // window.location.href = "https://www.baidu.com/"; // window.location = "https://www.baidu.com/"; location = "https://www.baidu.com/"; }; }; </script> </head> <body> <input id="btn" type="button" value="百度一下,你就知道" /> </body> </html>
本文章地址http://www.vzeo.com/news/xuetang/800589.html 由 友站网 编辑整理,转载请注明出处