如何在 HTML 中指定元素在页面加载时自动获得焦点?
htmlweb developmentfront end technology更新于 2025/8/14 15:08:17
在 HTML 中使用 autofocus 属性指定元素在页面加载时自动获得焦点 −
示例
您可以尝试运行以下代码,了解如何在 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>
相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

