This article mainly introduces JS to add a jump function similar to a tag to the button. Friends who need it can refer to the
method
window.location.href = "要跳转的URL";
or
window.location = "要跳转的URL";
or
location = "要跳转的URL";
example
<!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>
The above is the detailed content of How to add jump function to button using JS (similar to a tag). For more information, please follow other related articles on the PHP Chinese website!