Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize click-for-picture in jquery

Shulou Source: shulou.com Published: 2022-05-31 20:22:26 09月21日 Update

This article introduces the relevant knowledge of "how to click for picture in jquery". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Implementation method: 1, use click () to bind the button element click event, and set the handler function, syntax "button element .click (function () {});"; 2, in the handler function, use attr () to modify the picture address, syntax "$(" img "). Attr (" src "," new map address ")".

The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.

The method of clicking and swapping pictures in jquery:

Realize the idea:

Bind the click event to the button element with click () and set the event handler

In the handler, modify the address of the picture with attr () (that is, modify the value of the src attribute of the img element)

Implementation code: click the button to change the picture

$(document) .ready (function () {$("button") .click (function () {$("img"). Attr ("src", "img/1.jpg");})

Click the button to change the picture

Description:

The tag defines the image in the HTML page.

Tags have two required attributes: src and alt.

The src attribute of the tag is required, which specifies the URL of the image.

The attr () method sets the attribute value of the specified element, and when you use this method to modify the

The src attribute of the tag is to change the image.

This is the end of the content of "how to click for picture in jquery". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Pictures elements attributes buttons functions methods tags processing events addresses content images more knowledge grammar utility learning and then two code Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Shulou Information Redmi Linux vpn