如何指定元素应该在页面加载时在 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>
广告
数据结构
计算机网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言编程
C++
C#
MongoDB
MySQL
JavaScript
PHP