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

 找回密码
 注册
搜索

Javascript 使用focus 设置文本框焦点

[复制链接]
发表于 2011-4-8 15:30:06 | 显示全部楼层 |阅读模式
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>
复制代码

手机版|大马资讯论坛  

GMT+8, 2024-3-29 20:21 , Processed in 0.025626 second(s), 13 queries , File On.

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表