Thuộc tính tự động lấy nét Thời gian nhập của HTML DOM đặt / trả về liệu Thời gian nhập có được tập trung 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
inputTimeObject.autofocus
- Đặt tự động lấy nét thành booleanValue
inputTimeObject.autofocus = booleanValue
Giá trị Boolean
Ở đây, “booleanValue” có thể là như 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 đầu tiên. |
| 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 thời gian đầu vào tài sản -
<!DOCTYPE html>
<html>
<head>
<title>Input Time autofocus</title>
<style>
form {
width:70%;
margin: 0 auto;
text-align: center;
}
* {
padding: 2px;
margin:5px;
}
input[type="button"] {
border-radius: 10px;
}
</style>
</head>
<body>
<form>
<fieldset>
<legend>Time-autofocus</legend>
<label for="TimeSelect">Exam Time:
<input type="time" id="TimeSelect" value="10:00" autofocus>
</label>
<input type="button" onclick="removeAutofocus()" value="Remove Autofocus">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var inputTime = document.getElementById("TimeSelect");
divDisplay.textContent = 'Autofocus: '+inputTime.autofocus;
function removeAutofocus() {
inputTime.autofocus = false;
divDisplay.textContent = 'Autofocus: '+inputTime.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 tự động lấy nét' nút -
Sau khi nhấp vào ‘Xóa tự động lấy nét’ nút -