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)06/01 Report--
This article mainly introduces the relevant knowledge of "jquery set text box read-only method". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "jquery set text box read-only method" can help you solve the problem.
Methods: 1, use the "$(input element)" statement to obtain the text box element object; 2, use the attr () method to set the text box read-only, set the readonly attribute value to readonly, and the syntax is "text box element object .attr (" readonly "," readonly ")".
The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.
How to set the text box to read-only by jquery
1. Use the "$(input element)" statement to get the text box element object
$is another name for jQuery.
JQuery is a function provided by the jQuery library. (it seems to be more than just a function, because there is also a use like $.ajax (options), which is equivalent to jQuery.ajax (options)).
The function of this function is to find and select elements in the html document according to the parameters in (). One of the functions is to replace GetElementByID, but it can be not only an ID, but also a variety of selectors.
For example:
$(document) is to select the entire document object
2. Attr method
The attr () method sets or returns the properties and values of the selected element.
When the method is used to return a property value, it returns the value of the first matching element.
When this method is used to set property values, one or more attribute / value pairs are set for matching elements.
Grammar
Returns the value of the property:
$(selector) .attr (attribute)
Set properties and values:
$(selector) .attr (attribute,value)
The readonly property specifies that the input field is read-only.
Read-only fields cannot be modified. However, users can still use the tab key to switch to the field and select or copy its text.
Examples are as follows:
Runoob.com $(document) .ready (function () {$("button") .click (function () {$('input') .attr ("readonly", "readonly");}); set the text box to read-only
Output result:
This is the end of the introduction to "how to set the text box read-only by jquery". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
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.