Three ways to jump to a page by clicking a button tag in HTML

Three ways to jump to a page by clicking a button tag in HTML

Method 1: Using the onclick event

<input type="button" value="button"
onclick="javascript:window.location.href='http://www.baidu.com/'" />

Or use the button tag directly

<button onclick="window.location.href = 'https://www.baidu.com/'">Baidu</button>

Method 2: Add an a tag to the button tag

<a href="http://www.baidu.com/">
    <button>Baidu</button>
</a>

Or use

<a href="http://www.baidu.com/"><input type="button" value='Baidu'></a>

Method 3: Using JavaScript Function

<script>
function jump(){
 window.location.href="http://www.baidu.com/";
}
</script>
<input type="button" value="Baidu" onclick=javascript:jump() />
// Or <input type="button" value="Baidu" onclick="jump()" />
// or <button onclick="jump()">Baidu</button>

Summarize

The above are three methods introduced by the editor to achieve page jump by clicking the button tag in HTML. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

<<:  The most common declaration merge in TS (interface merge)

>>:  Docker deploys Mysql, .Net6, Sqlserver and other containers

Recommend

Docker generates images through containers and submits DockerCommit in detail

Table of contents After creating a container loca...

JavaScript implements checkbox selection function

This article example shares the specific code of ...

JavaScript+html to implement front-end page sliding verification (2)

This article example shares the specific code of ...

Reasons and solutions for not being able to detect array changes in Vue2

Table of contents Workaround Why can't I moni...

HTML+CSS+JS sample code to imitate the brightness adjustment effect of win10

HTML+CSS+JS imitates win10 brightness adjustment ...

Native javascript+CSS to achieve the effect of carousel

This article uses javascript+CSS to implement the...

How to change the MySQL database directory location under Linux (CentOS) system

How to change the MySQL database directory locati...

Design theory: Why are we looking in the wrong place?

I took the bus to work a few days ago. Based on m...

Methods of adaptive web design (good access experience on mobile phones)

1. Add the viewport tag to the HTML header. At th...

react-beautiful-dnd implements component drag and drop function

Table of contents 1. Installation 2.APi 3. react-...

A brief discussion on why daemon off is used when running nginx in docker

I'm very happy. When encountering this proble...

MySQL replication table details and example code

MySQL replication table detailed explanation If w...

A brief summary of vue keep-alive

1. Function Mainly used to preserve component sta...

Detailed example of database operation object model in Spring jdbc

Detailed example of database operation object mod...