Thuộc tính disabled của Fieldset dùng để vô hiệu hóa (disable) nhóm các phần tử bên trong fieldset. Khi đặt true, các phần tử con bị vô hiệu hóa (hiển thị xám, không tương tác được). Mặc định là false (kích hoạt).
Cú pháp
Đặt thuộc tính disabled:
fieldsetObject.disabled = true|false
Lấy giá trị:
fieldsetObject.disabled
Ví dụ
Ví dụ bật/tắt fieldset bằng hai nút:
<!DOCTYPE html>
<html>
<head>
<script>
function disableFieldset() {
document.getElementById("FieldSet1").disabled = true;
}
function enableFieldset() {
document.getElementById("FieldSet1").disabled = false;
}
</script>
</head>
<body>
<h1>Form mẫu</h1>
<form>
<fieldset id="FieldSet1">
<legend>Thông tin người dùng:</legend>
Tên: <input type="text"><br>
Địa chỉ: <input type="text"><br>
Tuổi: <input type="text">
</fieldset>
</form>
<br>
<button onclick="enableFieldset()">KÍCH HOẠT</button>
<button onclick="disableFieldset()">VÔ HIỆU HÓA</button>
<p>Nhấn nút để bật/tắt fieldset</p>
</body>
</html>
Kết quả
Ban đầu các trường nhập liệu hoạt động bình thường.
Sau khi nhấn "VÔ HIỆU HÓA", tất cả trường trong fieldset chuyển màu xám, không nhập được.
Nhấn "KÍCH HOẠT" để phục hồi.
Giải thích
- Fieldset
id="FieldSet1"nhóm 3 trường input. - Hai nút gọi
enableFieldset()(disabled=false) vàdisableFieldset()(disabled=true). - Thay đổi thuộc tính
disabledcủa fieldset ảnh hưởng đến tất cả phần tử con.