HTML DOM中的Input Submit autofocus屬性用於設置或返回在頁麵加載時Input Submit Field是否應獲得焦點。它反映了HTML自動對焦屬性。
用法:
- 它返回自動對焦屬性。
submitObject.autofocus
- 用於設置自動對焦屬性。
submitObject.autofocus = "true|false"
屬性值:
- true:它設置提交按鈕的焦點。
- false:它是默認值。它定義了提交按鈕字段不被關注。
返回值:它返回一個布爾值,該值表示提交字段是否自動聚焦。
範例1:本示例返回輸入提交自動對焦屬性。
<!DOCTYPE html>
<html>
<head>
<title>
HTML DOM Input Submit autofocus Property
</title>
</head>
<body style="text-align:center;">
<h1>
GeeksForGeeks
</h1>
<h2>
HTML DOM Input Submit autofocus Property
</h2>
<form id="myGeeks" action="#" method="get" target="_self">
<input type = "submit" id = "Geeks"
name="myGeeks" value = "Submit @ geeksforgeeks" autofocus>
</form>
<p>
click on below button to return the Property
</p>
<button onclick = "myGeeks()">
Click Here!
</button>
<p id = "GFG"style="font-size:25px;"></p>
<!-- Script to set submit disbled Property -->
<script>
function myGeeks() {
var btn = document.getElementById("Geeks").autofocus;
document.getElementById("GFG").innerHTML =btn;
}
</script>
</body>
</html>
輸出:
單擊按鈕之前:
單擊按鈕後:
範例2:本示例說明如何設置“輸入提交”自動對焦屬性。
<!DOCTYPE html>
<html>
<head>
<title>
HTML DOM Input Submit autofocus Property
</title>
</head>
<body style="text-align:center;">
<h1>
GeeksForGeeks
</h1>
<h2>
HTML DOM Input Submit autofocus Property
</h2>
<form id="myGeeks" action="#" method="get" target="_self">
<input type = "submit" id = "Geeks" name="myGeeks"
value = "Submit @ geeksforgeeks" autofocus>
</form>
<p>
click on below button to set the Property
</p>
<button onclick = "myGeeks()">
Click Here!
</button>
<p id = "GFG"style="font-size:25px;"></p>
<!-- Script to set submit autofocus Property -->
<script>
function myGeeks() {
var btn = document.getElementById("Geeks").autofocus
= false;
document.getElementById("GFG").innerHTML = btn;
}
</script>
</body>
</html>
輸出:
單擊按鈕之前:
單擊按鈕後:
支持的瀏覽器:下麵列出了DOM Input Submit autofocus屬性支持的瀏覽器:
- 穀歌瀏覽器
- Internet Explorer 10.0
- Firefox
- Opera
- Safari
相關用法
- HTML Input Submit value用法及代碼示例
- HTML Input Submit name用法及代碼示例
- HTML Input Submit type用法及代碼示例
- HTML Input Submit disabled用法及代碼示例
- HTML Input Submit form用法及代碼示例
- HTML Input Submit formNoValidate用法及代碼示例
- HTML Input Submit formMethod用法及代碼示例
- HTML Input Submit formTarget用法及代碼示例
- HTML Input Submit formAction用法及代碼示例
- HTML Input Submit defaultvalue用法及代碼示例
- HTML Input Submit formEnctype用法及代碼示例
- HTML Input URL autofocus用法及代碼示例
- HTML Input Number autofocus用法及代碼示例
- HTML Input Range autofocus用法及代碼示例
- HTML Input Search autofocus用法及代碼示例
注:本文由純淨天空篩選整理自ManasChhabra2大神的英文原創作品 HTML | DOM Input Submit autofocus Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。