在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>