Thuộc tính tự động lấy nét của URL đầu vào HTML DOM đặt / trả về liệu URL đầu vào 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
inputURLObject.autofocus
- Đặt tự động lấy nét thành booleanValue
inputURLObject.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 ví dụ về Tự động lấy nét URL đầu vào tài sản -
<!DOCTYPE html>
<html>
<head>
<title>Input URL 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>URL-autofocus</legend>
<label for="URLSelect">URL :
<input type="url" id="URLSelect" placeholder="https://www.google.com" autofocus>
</label>
<input type="button" onclick="removeAutofocus()" value="Remove Autofocus">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var inputURL = document.getElementById("URLSelect");
divDisplay.textContent = 'Autofocus: '+inputURL.autofocus;
function removeAutofocus() {
inputURL.autofocus = false;
divDisplay.textContent = 'Autofocus: '+inputURL.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 -