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

What are the operation properties of jQuery

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

In this issue, the editor will bring you about the operational attributes of jQuery. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

1. Operation attribute 1. Read attribute value: attr (attribute name)

Gets the attribute value of the first matching element. This method makes it easy to get the value of an attribute from the first matching element. Returns undefined if the element does not have the corresponding attribute

2. Modify the attribute value (1) attr (key,value)

Set an attribute value for all matching elements

(2) attr (key,fn)

'key': represents the attribute name

'fn': represents a function and takes the attribute value of the function as the value of the attribute represented by key

Sets a calculated attribute value for all matching elements. Instead of providing a value, it provides a function with the value calculated by this function as the attribute value

(3) attr ({attribute name 1: attribute value, attribute name 2: attribute value}) 3. Delete attribute: removeAttr (attribute name)

Remove an attribute from each matching element

Document .ok {color: red;} go to Baidu

$(function () {let str = $('a') .attr ('href') / / Select the a tag to assign the attribute of href to str console.log (str) / / $('input'). Attr (' value','123') $('input'). Attr (' value',function () {/ / assign the value of the function to value, note that the function must have a return value of let s = 0; for (let item1

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