Posted in Javascript onMay 30, 2017
方法
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>
以上所述是小编给大家介绍的JS给按钮添加跳转功能类似a标签,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!
JS给按钮添加跳转功能类似a标签
- Author -
loetca声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@