方法
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标签,希望对大家有所帮助
如对本文有疑问, 点击进行留言回复!!
使用纯前端JavaScript实现Excel导入导出方法过程详解
微信小程序完美解决scroll-view高度自适应问题的方法
网友评论