In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces jquery how to add an attribute and value related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that after reading this jquery how to add an attribute and value article will have a harvest, let's take a look at it.
Two methods: 1, use attr () to add, syntax "element object .attr (" attribute name "," value ") or" element object .attr ({attribute: value}) "; 2, use prop () to add, syntax" element object .prop ("attribute", "value") or "element object .prop ({attribute: value})".
The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.
Jquery can add attributes and values to an element in two ways:
Use attr ()
Use prop ()
Both the prop () method and the attr () method are used to get or set the HTML attribute of an element, and the syntax is similar.
1. Use attr ()
Add a syntax for attributes and values:
Element object .attr ("attribute name", "value") element object .attr ({attribute: value})
Example: let the text box add the disabled property setting is not editable
$(document) .ready (function () {$("button") .click (function () {$("textarea") .attr ("disabled", "disabled"); / / $("textarea") .attr ({disabled:true}) );})
Make textarea uneditable
2. Use prop ()
Add a syntax for attributes and values:
Element object .prop (attribute, value) element object .prop ({attribute: value})
Example: add a readonly property to the input box to set read-only
$(document) .ready (function () {$("button") .click (function () {$("input") .prop ("readonly", "readonly"); / / $("input") .prop ({readonly:true}) });}); .intro {font-size: 120%; color: red } add a read-only attribute to input
Description:
The prop () method is similar to the attr () method, but there are fundamental differences. JQuery officially recommends that attributes with values of true and false, such as checked, selected and disabled, be operated using the prop () method, while other attributes are recommended to use the attr () method.
This is the end of the article on "how to add an attribute and value to jquery". Thank you for reading! I believe you all have a certain understanding of "how to add an attribute and value to jquery". If you want to learn more, you are welcome to follow the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.