Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize click-for-picture in jquery

2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report