Get the App
SLTechnology News&Howtos  ›  Development  › 

How jquery changes elements to read-only

Shulou Source: shulou.com Published: 2022-06-02 06:57:10 11月04日 Update

Editor to share with you how jquery changes the elements to read-only. I hope you will get something after reading this article. Let's discuss it together.

Jquery changes the element to read-only method: 1, use the "$(specified element)" statement to get the specified element object; 2, use the attr () method and readonly attribute to change the element into a read-only state, and the syntax is "element object .attr (" readonly "," readonly ")".

The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.

In css, you can use the attr () method to change the element to a read-only state, and the attr () method to set or return the property value of the selected element.

The syntax is:

$(selector) .attr (attribute,value)

Just set the readonly property of the element to readonly. The readOnly property sets or returns whether the text field is read-only.

Let's take a look at how to make a text box element read-only through an example. Examples are as follows:

Function demo () {$("input [name=demo]") .attr ("readonly", "readonly");}

Tags: Elements attributes methods states objects examples articles grammars finishes tutorials texts more versions environments computers knowledge systems results industries statements Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info MySQL macOS Xiaomi vpn