Home > Web Front-end > JS Tutorial > How to add jump function to button using JS (similar to a tag)

How to add jump function to button using JS (similar to a tag)

黄舟
Release: 2017-05-31 10:19:31
Original
2786 people have browsed it

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";
Copy after login

or

window.location = "要跳转的URL";
Copy after login

or

location = "要跳转的URL";
Copy after login

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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template