大马资讯论坛 - 马来西亚中文资讯平台

标题: Javascript 使用focus 设置文本框焦点 [打印本页]

作者: 资讯王    时间: 2011-4-8 15:30
标题: Javascript 使用focus 设置文本框焦点
Javascript 使用focus 设置文本框焦点
The javascript code below shows how to set the focus on an Input Field / Form Field / Html Element (Textbox) when the page is loaded.
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function setFocus()
  5. {
  6.      document.getElementById("name").focus();
  7. }
  8. </script>
  9. </head>

  10. <body onload="setFocus()">
  11.   <form>
  12.        Name: <input type="text" id="name" size="30"><br />
  13.        Surname: <input type="text" id="surname" size="30">
  14.   </form>
  15. </body>

  16. </html>
复制代码





欢迎光临 大马资讯论坛 - 马来西亚中文资讯平台 (http://freeinfo.com.my/) Powered by Discuz! X3.3