输入电子邮件自动对焦属性HTML DOM中的DOM用于设置或返回页面加载时输入电子邮件字段是否应获得焦点。它反映了HTML自动对焦属性。
语法如下:
- 它返回自动对焦属性。
emailObject.autofocus
- 用于设置自动对焦属性。
emailObject.autofocus = "true|false"
属性值:
true:设置电子邮件字段的焦点
false:为默认值。它定义了电子邮件字段没有得到关注
返回值:它返回一个布尔值, 该值表示电子邮件字段是否获得自动聚焦。
例子:本示例返回"输入电子邮件"自动聚焦属性。
<!DOCTYPE html>
<html>
<head>
<title>
HTML DOM Input Email autofocus Property
</title>
</head>
<body>
<h1> lsbin</h1>
<h2>DOM Input Email autofocus Propertyt</h2>
E-mail: <input type = "email" id = "email"
value = "careers@lsbin.org" autofocus>
<button onclick = "myGeeks()">
Click Here!
</button>
<p id = "GFG" style = "font-size:25px;color:green;"></p>
<!-- Script to access input element with
type email attribute -->
<script>
function myGeeks() {
var em = document.getElementById("email").autofocus;
document.getElementById("GFG").innerHTML = em;
}
</script>
</body>
</html>
输出如下:
在单击按钮之前:
单击按钮后:
示例2:本示例设置"输入电子邮件"自动对焦属性。
<!DOCTYPE html>
<html>
<head>
<title>
HTML DOM Input Email autofocus Property
</title>
</head>
<body style = "text-align:center;">
<h1> lsbin</h1>
<h2>DOM Input Email autofocus Property</h2>
E-mail: <input type = "email" id = "email"
value = "careers@lsbin.org" autofocus>
<button onclick = "myGeeks()">
Click Here!
</button>
<p id = "GFG" style = "font-size:25px;color:green;"></p>
<!-- Script to access input element with
type email attribute -->
<script>
function myGeeks() {
var em = document.getElementById("email").autofocus
= "false"
document.getElementById("GFG").innerHTML
= "The value of the autofocus attribute"
+ " was changed to " + em;
}
</script>
</body>
</html>
输出:
在单击按钮之前:
单击按钮后:
支持的浏览器:支持的浏览器DOM输入电子邮件自动对焦属性下面列出:
- 谷歌浏览器
- IE浏览器
- 火狐浏览器
- 歌剧
- 苹果浏览器