Thuộc tính tự động lấy nét màu đầu vào HTML DOM đặt / trả về liệu Màu đầu vào có được lấy nét khi tải trang đầu tiên hay không.
Cú pháp
Sau đây là cú pháp -
- Trả về giá trị boolean - true / false
inputColorObject.autofocus
- Đặt tự động lấy nét sang booleanValue
inputColorObject.autofocus = booleanValue
Giá trị Boolean
Đây, “ booleanValue ”Có thể là sau -
| booleanValue | Chi tiết |
|---|---|
| true | Nó xác định rằng đầu vào sẽ được lấy nét tự động khi tải trang. |
| sai | Đây là giá trị mặc định và đầu vào không được lấy nét tự động. |
Ví dụ
Hãy để chúng tôi xem ví dụ về Tự động lấy nét màu đầu vào tài sản -
<!DOCTYPE html>
<html>
<head>
<title>Input Color Autofocus</title>
</head>
<body>
Color Picker: <input type="color" id="Color" autofocus>
<button onclick="removeAutoFocus()">Remove Auto Focus</button>
<div id="divDisplay"></div>
<script>
var divDisplay = document.getElementById("divDisplay");
var inputColor = document.getElementById("Color");
divDisplay.textContent = 'Autofocus: '+inputColor.autofocus function removeAutoFocus() {
if(inputColor.autofocus == true){
inputColor.autofocus = false;
divDisplay.textContent = 'Autofocus: '+inputColor.autofocus
}
}
</script>
</body>
</html> Đầu ra
Điều này sẽ tạo ra kết quả sau -
Trước khi nhấp vào ' Xóa tiêu điểm tự động Nút '-
Sau khi nhấp vào ‘ Xóa tiêu điểm tự động Nút '-