Thuộc tính bị vô hiệu hóa HTML


Định nghĩa và Cách sử dụng

Thuộc disabledtính là một thuộc tính boolean.

Khi xuất hiện, nó chỉ định rằng phần tử nên bị vô hiệu hóa.

Một phần tử bị vô hiệu hóa không thể sử dụng được.

Thuộc disabledtính có thể được đặt để ngăn người dùng sử dụng phần tử cho đến khi một số điều kiện khác được đáp ứng (như chọn hộp kiểm, v.v.). Sau đó, JavaScript có thể xóa giá trị bị vô hiệu hóa và làm cho phần tử có thể sử dụng lại được.


Áp dụng đối với

Thuộc disabledtính có thể được sử dụng trên các phần tử sau:

Các yếu tố Thuộc tính
<button> tàn tật
<fieldset> tàn tật
<input> tàn tật
<optgroup> tàn tật
<chú thích> tàn tật
<select> tàn tật
<textareosystem tàn tật

Các ví dụ

Ví dụ về nút

Một nút bị vô hiệu hóa:

<button type="button" disabled>Click Me!</button>

Ví dụ về tập trường

Vô hiệu hóa một nhóm các phần tử biểu mẫu có liên quan:

<fieldset disabled>
  <legend>Personalia:</legend>
  Name: <input type="text"><br>
  Email: <input type="text"><br>
  Date of birth: <input type="text">
</fieldset>

Ví dụ đầu vào

Biểu mẫu HTML có trường nhập bị tắt:

<form action="/action_page.php">
  First name: <input type="text" name="fname"><br>
  Last name: <input type="text" name="lname" disabled><br>
  <input type="submit" value="Submit">
</form>

Ví dụ về nhóm chọn

Một nhóm tùy chọn bị vô hiệu hóa:

<select>
  <optgroup label="German Cars" disabled>
    <option value="mercedes">Mercedes</option>
    <option value="audi">Audi</option>
  </optgroup>
</select>

Ví dụ về tùy chọn

Danh sách thả xuống với một tùy chọn bị vô hiệu hóa:

<select>
  <option value="volvo" disabled>Volvo</option>
  <option value="saab">Saab</option>
  <option value="vw">VW</option>
  <option value="audi">Audi</option>
</select>

Chọn ví dụ

Danh sách thả xuống bị vô hiệu hóa:

<select disabled>
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="mercedes">Mercedes</option>
  <option value="audi">Audi</option>
</select>

Ví dụ về Textarea

Vùng văn bản bị vô hiệu hóa:

<textarea disabled>
At w3schools.com you will learn how to make a website. We offer free tutorials in all web development technologies.
</textarea>

Hỗ trợ trình duyệt

Thuộc disabledtính này có hỗ trợ trình duyệt sau cho từng phần tử:

Element
button Yes Yes Yes Yes Yes
fieldset Yes Not supported Yes 7.0 Yes
input 1.0 6.0 1.0 1.0 1.0
optgroup 1.0 8.0 Yes Yes Yes
option 1.0 8.0 1.0 Yes Yes
select Yes Yes Yes Yes Yes
textarea Yes Yes Yes Yes Yes