Home > Article > Web Front-end > How to set button attributes in javascript
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 ".
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!