Home > Web Front-end > JS Tutorial > body text

How to set button attributes in javascript

藏色散人
Release: 2021-06-30 10:22:13
Original
6949 people have browsed it

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;
Copy after login

(2) The setting button is clickable

document.getElementById("bt1").disabled=false;
Copy after login

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);
Copy after login

(1) The setting button is clickable

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

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"> 不可点击
Copy after login

[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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template