Get the App
SLTechnology News&Howtos  ›  Development  › 

How to add read-only or disable attributes to tags by jquery

Shulou Source: shulou.com Published: 2022-06-01 04:41:03 09月27日 Update

This article mainly introduces jquery how to add read-only or disabled attributes to the tag related knowledge, the content is detailed and easy to understand, the operation is simple and fast, with a certain reference value, I believe that after reading this jquery how to add read-only or disabled attributes to the tag article will have a harvest, let's take a look.

1. JQuery

JQuery is a JavaScript library.

JQuery greatly simplifies JavaScript programming.

JQuery is easy to learn.

Example:

$(document) .ready (function () {$("p") .click (function () {$(this). Hide ();})

Source code:

Rookie tutorial (runoob.com) $(document) .ready (function () {$("p") .click (function () {$(this). Hide ();})

If you click me, I will disappear.

Keep clicking on me!

Then click on me!

Running result:

The running result of the above picture will disappear as long as you click on the text. Interested partners can go down and have a try.

Second, about the readonly attribute

Example 1. Jquery sets the readonly property

$('input') .attr ("readonly", "readonly") / / set the input element to readonly$ (' input') .removeAttr ("readonly"); / / remove the readonly attribute if ($('input'). Attr ("readonly") = true) of the input element / / determine whether the readonly attribute has been set for the input element

Example 2. Methods for setting the readonly attribute and canceling the readonly attribute for an element

$('input'). Attr ("readonly", true) / / set the input element to readonly$ (' input'). Attr ("readonly", false) / / remove the readonly attribute of the input element $('input'). Attr ("readonly", "readonly") / / set the input element to readonly$ (' input'). Attr ("readonly", ") / remove the readonly attribute of the input element. Jquery sets the disabled attribute.

Example 1. Jquery sets the disabled property

$('input') .attr ("disabled", "disabled") / / set the input element to disabled$ (' input') .removeAttr ("disabled"); / / remove the disabled attribute if ($('input'). Attr ("disabled") = true) of the input element / / determine whether the disabled attribute has been set for the input element

Example 2. Methods for setting the disabled attribute and canceling the disabled attribute for an element

$('input'). Attr ("disabled", true) / / sets the input element to disabled$ (' input'). Attr ("disabled", false) / / removes the disabled attribute of the input element $('input'). Attr ("disabled", "disabled") / / sets the input element to disabled$ (' input'). Attr ("disabled") ") / / remove the disabled attribute of the input element. 4. Jquery dynamically add the readonly read-only attribute of the text box $(" # test ") .attr ({" readonly ":" readonly "}) / / add readonly attribute / / or $("# ID"). Attr ({readonly: 'true'}); $("# test"). RemoveAttr ("readonly"); / / remove the readonly attribute on "how to add read-only or disable attributes to tags". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how jquery adds read-only or disabled attributes to tags". If you want to learn more, you are welcome to follow the industry information channel.

Tags: Attributes elements tags knowledge content methods articles results learning running picture above value interest dynamics examples guys buddies easy to operate tutorials text Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Redmi Shulou Tech Info vpn macOS