Thuộc tính lấy nét tự động của Tuần nhập liệu đặt / trả về liệu Tuần nhập liệu 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
inputWeekObject.autofocus
- Đặt tự động lấy nét thành booleanValue
inputWeekObject.autofocus = booleanValue
Giá trị Boolean
Đây, “booleanValue” có thể như sau -
| booleanValue | Chi tiết |
|---|---|
| Đúng | 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 một ví dụ về Tự động lấy nét theo Tuần đầu vào tài sản -
<!DOCTYPE html>
<html>
<head>
<title>Input Week 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>Week-autofocus</legend>
<label for="WeekSelect">Target Week :
<input type="week" id="WeekSelect" value="2019-W24" autofocus>
</label>
<input type="button" onclick="removeAutofocus()" value="Remove Autofocus">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var inputWeek = document.getElementById("WeekSelect");
divDisplay.textContent = 'Autofocus: '+inputWeek.autofocus;
function removeAutofocus() {
inputWeek.autofocus = false;
divDisplay.textContent = 'Autofocus: '+inputWeek.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 -