Home >Web Front-end >JS Tutorial >How to set disabled attribute in jquery?

How to set disabled attribute in jquery?

青灯夜游
青灯夜游Original
2020-11-18 13:44:0911852browse

In jquery, you can use the attr() method to set the disabled attribute. There are two syntax formats: "$('element').attr("disabled",true)" or "$('element" ').attr("disabled","disabled")".

How to set disabled attribute in jquery?

The operating environment of this tutorial: windows10 system, jquery2.2.4, this article is applicable to all brands of computers.

[Related recommendations: jQuery video tutorial]

The disabled attribute specifies that the input element should be disabled.

A disabled input element is neither available nor clickable. The disabled attribute can be set until some other condition is met (such as a checkbox being selected, etc.). Then, you need to use JavaScript to remove the disabled value and switch the value of the input element to available.

jquery sets the disabled attribute

//两种方法设置disabled属性
$('#areaSelect').attr("disabled",true);
$('#areaSelect').attr("disabled","disabled");

attr() method sets or returns the attributes and values ​​of the selected element. When this method is used to set attribute values, one or more attribute/value pairs are set for the matching element.

jquery removes disabled attribute

//三种方法移除disabled属性
$('#areaSelect').attr("disabled",false);
$('#areaSelect').removeAttr("disabled");
$('#areaSelect').attr("disabled","");

Get s:textfield and set its disabled attribute:

The code is as follows:

functiondisableTextfieldofAccountDiv(element,val) {
$(element).find(":textfield").attr('disabled',val);
}

For more programming-related knowledge, please visit: Programming Learning! !

The above is the detailed content of How to set disabled attribute in jquery?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn