在body标签中添加语句:onload="document.getElementById('userid ').focus()"即可。
其中 userid 为获得焦点的元素id。
<html>
<body onload="document.getElementById('username ').focus()" >
<form method="post">
<table>
<tr>
<td>用户名:</td>
<td><input type="text" id="userid" name="username " /></td>
</tr>
<tr>
<td >密 码:</td>
<td><input type="password" id="password" name="password" /></td>
</tr>
</table>
</form>
</body>
</html>
本文介绍了一种通过在HTML body标签中使用onload事件来实现页面加载完成后自动将光标定位到指定输入框的方法。该方法适用于需要快速进行输入操作的场景,如登录页面等。
933

被折叠的 条评论
为什么被折叠?



