```Among them, the `href` attribute is used to specify the link to jump to"> html click on the picture to jump to the picture-Golang-php.cn

html click on the picture to jump to the picture

PHPz
Release: 2023-05-09 10:24:07
Original
6967 people have browsed it

HTML Clicking on an image to jump to an image is a commonly used technique in web design, which allows users to jump to other web pages or images by clicking on an image. This article will introduce how to use HTML code to achieve this effect.

1. Use hyperlinks to jump to images

First, use the following code in HTML to jump to other pages through hyperlinks:

Copy after login

Among them, thehrefattribute is used to specify the link address to be jumped, and thesrcattribute in theimgtag is used to specify the URL of the image.

For example, the following is an example of a hyperlink image that jumps to a Baidu page:

Copy after login

To open a hyperlink image in a new window, you can usetarget="_blank "attribute, as shown below:

Copy after login

2. Use JavaScript to jump to images

In addition to using hyperlinks, you can also use JavaScript to control the jump to after clicking on the image. target page. This needs to be implemented through JS code. Bind aclickevent to the image. When the user clicks, the page will jump through the JS code.

The sample code is as follows:

 
Copy after login

Among them,location.hrefin the JS code is used to specify the target page address to jump to.

3. Jump to another picture from a picture

If you want to jump to another picture after clicking on the picture, you can use JavaScript to achieve this.

First, you need to place two image tags in HTML and set their initial display state, as shown below:

 
Copy after login

Then, bind aclick in the JS codeevent, and switch the display status of the two image tags in the event handler function, as shown below:

 
Copy after login

Run the above code, when the image is clicked, it will be displayed between the two image tags. switch between.

Summary:

Using hyperlinks and JavaScript, image jumps in web pages can be achieved. We can choose the most appropriate method to achieve image jumps based on actual needs. Whether using hyperlinks or JavaScript, you can achieve simple and effective image jumps.

The above is the detailed content of html click on the picture to jump to the picture. For more information, please follow other related articles on the PHP Chinese website!

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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!