Home  >  Article  >  Web Front-end  >  How to set button attributes in javascript

How to set button attributes in javascript

藏色散人
藏色散人Original
2021-06-30 10:22:136956browse

How to set button attributes in javascript: 1. Set the clickability or non-clickability of the button through disabled in js; 2. Set whether the button is clickable through attr; 3. Add the attribute "disabled="true" to the tag ".

How to set button attributes in javascript

The operating environment of this article: windows7 system, javascript version 1.8.5, Dell G3 computer.

How to set button attributes in javascript?

Set the clickability or non-clickability of the button in javascript

1. Set the clickability or non-clickability of the button in js. The default is clickable

( 1) The setting button is not clickable

document.getElementById("bt1").disabled=ture;

(2) The setting button is clickable

document.getElementById("bt1").disabled=false;

2. The setting button in jq is clickable or non-clickable. The default is clickable

(1) The setting button is not clickable

$("#bt1").attr("disabled",ture);

(1) The setting button is clickable

$("#bt1").attr("disabled",false);

3. The setting button in the label is not clickable

Add the attribute disabled=" in the label true".

For buttons whose input type is button, submit, or reset, as long as they have the disabled attribute, regardless of whether this attribute has a value or not, they are not clickable; on the contrary, they can be clicked without this attribute. .

For example

<input type="button" disabled> 不可点击
<input type="button" disabled="true"> 不可点击
<input type="button" disabled="disabled"> 不可点击

[Related recommendations: javascript advanced tutorial]

The above is the detailed content of How to set button attributes in javascript. 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