如何在 HTML 中指定元素在页面加载时自动获得焦点?
使用 autofocus 属性可在 HTML 中指定元素在页面加载时自动获得焦点 -
示例
你可以尝试运行以下代码来学习如何在 HTML 中实现 autofocus 属性 -
<!DOCTYPE html>
<html>
<body>
<p>Click on the below button to generate an alert box.</p>
<button type = "button" autofocus onclick = "alert('Welcome!')">Result</button>
</body>
</html>
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
安卓
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP