我正在尝试在页面加载时将默认焦点设置在输入框上(例如:google)。我的页面非常简单,但是我不知道该怎么做。
到目前为止,这是我得到的:
<html>
<head>
 <title>Password Protected Page</title>
 <script type="text/javascript">
 function FocusOnInput()
 {
 document.getElementById("PasswordInput").focus();
 }
 </script>
 <style type="text/css" media="screen">
  body, html {height: 100%; padding: 0px; margin: 0px;}
  #outer {width: 100%; height: 100%; overflow: visible; padding: 0px; margin: 0px;}
  #middle {vertical-align: middle}
  #centered {width: 280px; margin-left: auto; margin-right: auto; text-align:center;}
 </style>
</head>
<body onload="FocusOnInput()">
 <table id="outer" cellpadding="0" cellspacing="0">
  <tr><td id="middle">
   <div id="centered">
  <form action="verify.php" method="post">
   <input type="password" name="PasswordInput"/>
  </form>
   </div>
  </td></tr>
 </table>
</body>
</html>
在正常工作的情况下为什么不起作用?
<html>
<head>
<script type="text/javascript">
function FocusOnInput()
{
     document.getElementById("InputID").focus();
}
</script>
</head>
<body onload="FocusOnInput()">
  <form>
       <input type="text" id="InputID">
  </form>
</body>
</html>
非常感谢帮助:-)