Thuộc tính lấy nét tự động lấy nét trong HTML DOM Input FileUpload đặt / trả về liệu Input FileUpload 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
inputFileUploadObject.autofocus
- Đặt tự động lấy nét thành booleanValue
inputFileUploadObject.autofocus = booleanValue
Giá trị Boolean
Đây, “booleanValue” có thể 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. |
| false | Đâ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ính năng lấy nét tự động tải tệp tin vào tệp tin tài sản -
<!DOCTYPE html>
<html>
<head>
<title>Input FileUpload 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>FileUpload-autofocus</legend>
<label for="FileSelect">Upload:
<input type="file" id="FileSelect" autofocus>
</label><br>
<input type="button" onclick="removeAutofocus()" value="Remove Autofocus">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var inputFile = document.getElementById("FileSelect");
divDisplay.textContent = 'Auto Focus:'inputFile.autofocus;
function removeAutofocus() {
inputFile.autofocus = false;
divDisplay.textContent = 'Auto Focus:'inputFile.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 -