HTML DOM輸入圖像自動對焦屬性用於設置或返回頁麵加載時輸入圖像字段是否應獲得焦點。它反映了HTML自動對焦屬性。
用法:
- 它返回自動對焦屬性。
imageObject.autofocus
- 用於設置自動對焦屬性。
imageObject.autofocus = "true|false"
屬性值:
- true:它設置輸入圖像的焦點。
- false:它是默認值。它定義了“輸入圖像”字段未獲得焦點。
返回值:它返回一個布爾值,該值表示圖像字段是否自動對焦。
範例1:本示例設置“輸入圖像”的自動對焦屬性。
<!DOCTYPE html>
<html>
<head>
<title>
HTML DOM Input Image autofocus Property
</title>
</head>
<body style="text-align:center;">
<h1 style="color:green;">
GeeksforGeeks
</h1>
<h4>
DOM Input Image autofocus Property
</h4>
<input id="myImage" formEnctype="application/x-www-form-urlencoded"
type="image" formtarget="#" src=
"https://media.geeksforgeeks.org/wp-content/uploads/gfg-40.png"
alt="Submit" width="48" height="48" formMethod="post"
autofocus>
<br>
<br>
<button onclick="my_geek()">Submit </button>
<h2 id="Geek_h" style="color:green;">
</h2>
<script>
function my_geek() {
// set Disabled Property.
var txt = document.getElementById(
"myImage").autofocus;
document.getElementById(
"Geek_h").innerHTML = txt;
}
</script>
</body>
</html>
輸出:
- 在單擊按鈕之前:
- 單擊按鈕後:
範例2:本示例返回Input Image自動對焦屬性。
<!DOCTYPE html>
<html>
<head>
<title>
HTML DOM Input Image autofocus Property
</title>
</head>
<body style="text-align:center;">
<h1 style="color:green;">
GeeksforGeeks
</h1>
<h4>DOM Input Image autofocus Property</h4>
<input id="myImage" formEnctype="application/x-www-form-urlencoded"
type="image" formtarget="#" src=
"https://media.geeksforgeeks.org/wp-content/uploads/gfg-40.png"
alt="Submit" width="48" height="48" formMethod="post"
autofocus>
<br>
<br>
<button onclick="my_geek()">Submit </button>
<h2 id="Geek_h" style="color:green;">
</h2>
<script>
function my_geek() {
// set Disabled Property.
var txt = document.getElementById(
"myImage").autofocus = false;
document.getElementById(
"Geek_h").innerHTML = txt;
}
</script>
</body>
</html>
輸出:
- 在單擊按鈕之前:
- 單擊按鈕後:
支持的瀏覽器:下麵列出了HTML DOM Input image autofocus屬性支持的瀏覽器:
- Googl Chrome 10.0
- Firefox 4.0
- Opera 11.0
- Safari 5.1
相關用法
- HTML Input URL autofocus用法及代碼示例
- HTML Input FileUpload autofocus用法及代碼示例
- HTML Input Email autofocus用法及代碼示例
- HTML Input DatetimeLocal autofocus用法及代碼示例
- HTML Input Search autofocus用法及代碼示例
- HTML Input Reset autofocus用法及代碼示例
- HTML Input Button autofocus用法及代碼示例
- HTML Input Month autofocus用法及代碼示例
- HTML Input Password autofocus用法及代碼示例
- HTML Input Range autofocus用法及代碼示例
- HTML Input Checkbox autofocus用法及代碼示例
- HTML Input Color autofocus用法及代碼示例
- HTML Input Week autofocus用法及代碼示例
- HTML Input Date autofocus用法及代碼示例
- HTML Input Number autofocus用法及代碼示例
注:本文由純淨天空篩選整理自ManasChhabra2大神的英文原創作品 HTML | DOM Input image autofocus Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。