HTML button标签的 autofocus 属性

返回到:HTML button标签

本节课,我们学习HTML button标签的 autofocus 属性。

autofocus 属性是一个 boolean(布尔) 属性。

autofocus 属性规定当页面加载时按钮应当自动地获得焦点。

HTML 4.01 与 HTML5之间的差异

autofocus 属性是 HTML5 <button> 标签的新属性。

HTML 与 XHTML之间的差异

在 XHTML 中, 不允许属性简写,autofocus 属性必须定义为 <button autofocus=”autofocus”>。

语法

<button type="button" autofocus>

浏览器支持

Internet Explorer 10, Firefox, Chrome, 和 Safari 支持autofocus 属性。

注意: Internet Explorer 9 以及更早IE版本不支持 autofocus 属性。

实例

按钮使用 autofocus 属性:

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>Web176教程(web176.com)</title> 
</head>
<body>

<button type="button" autofocus onclick="alert('Hello world!')">点我</button>

<p><strong>注意:</strong>  Internet Explorer 9 以及更早 IE 版本不支持 autofocus 属性。</p>
</body>
</html>

返回到:HTML button标签

作者:terry,如若转载,请注明出处:https://www.web176.com/html_element/7433.html

(0)
打赏 支付宝 支付宝 微信 微信
terryterry
上一篇 2022年12月2日 下午4:02
下一篇 2022年12月2日 下午4:21

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注