HTML DOM select autofocus 屬性返回並修改頁麵加載時下拉列表是否應該獲得焦點。
用法
以下是語法 -
1. 回歸自動對焦
object.autofocus
修改自動對焦
object.autofocus = true | false
示例
讓我們看一個 HTML DOM select autofocus 屬性的例子 -
<!DOCTYPE html>
<html>
<head>
<title>HTML DOM autofocus property</title>
<style>
body{
text-align:center;
color:#fff;
background:radial-gradient( circle farthest-corner at 23.1% 64.6%, rgba(129,125,254,1) 0%, rgba(111,167,254,1) 90% ) no-repeat;
height:100vh;
}
p{
font-weight:700;
font-size:1.1rem;
}
.drop-down{
display:block;
width:35%;
border:none;
font-weight:bold;
padding:10px;
margin:1rem auto;
background-color:#ffffff7a;
outline-color:black;
}
.btn{
background:orange;
border:none;
height:2rem;
border-radius:2px;
width:35%;
margin:2rem auto;
display:block;
color:#fff;
font-weight:bold;
outline:none;
cursor:pointer;
}
</style>
</head>
<body>
<h1>autofocus Property Example</h1>
<p>Hi, Select your favourite subject:</p>
<select class='drop-down' name="Drop Down List">
<option>Physics</option>
<option>Maths</option>
<option>Chemistry</option>
<option>English</option>
<option>Economics</option>
<option>Hindi</option>
<option>Biology</option>
</select>
<br>
<button onclick="disable()" class="btn">Disable Autofocus</button>
<script>
function disable() {
document.querySelector(".drop-down").autofocus = false;
}
</script>
</body>
</html>
輸出
這將產生以下輸出 -
點擊 ”Disable Autofocus” 按鈕以禁用下拉列表中的自動對焦。
相關用法
- HTML DOM Select add()用法及代碼示例
- HTML DOM Select size屬性用法及代碼示例
- HTML DOM Select remove()用法及代碼示例
- HTML DOM Select value屬性用法及代碼示例
- HTML DOM Select disabled屬性用法及代碼示例
- HTML DOM Select selectedIndex屬性用法及代碼示例
- HTML DOM Select type屬性用法及代碼示例
- HTML DOM Select length屬性用法及代碼示例
- HTML DOM Select multiple屬性用法及代碼示例
- HTML DOM Select form屬性用法及代碼示例
- HTML DOM Select用法及代碼示例
- HTML DOM Section用法及代碼示例
- HTML DOM Style overflowY屬性用法及代碼示例
- HTML DOM Style pageBreakAfter屬性用法及代碼示例
- HTML DOM Style transition屬性用法及代碼示例
- HTML DOM Style outlineOffset屬性用法及代碼示例
- HTML DOM Storage setItem()用法及代碼示例
- HTML DOM Style maxWidth屬性用法及代碼示例
- HTML DOM Style textAlignLast屬性用法及代碼示例
- HTML DOM Style borderBottomWidth屬性用法及代碼示例
注:本文由純淨天空篩選整理自AmitDiwan大神的英文原創作品 HTML DOM Select autofocus Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。