JavaScript中的Focus OnLoad

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JavaScript中的Focus OnLoad相关的知识,希望对你有一定的参考价值。

You can put the user's cursor inside a text box or put focus on select box as soon as your page is loaded. This helps ensure that visitors do not 'overlook' an important form item on your site and this snippet only uses one line of code!
  1. <!-- This part goes into your body tag -->
  2. <body OnLoad="document.myform.user.focus();">
  3.  
  4. <!-- You you just use the name of the form and field name within your form -->
  5. <form name="myform">
  6. Name: <input type="text" name="user" size="10">
  7. Email: <input type="text" name="email" size="10">
  8. </form>
  9.  
  10. </body>

以上是关于JavaScript中的Focus OnLoad的主要内容,如果未能解决你的问题,请参考以下文章

JavaScript-helloWorld

javaScript中的事件三

js中的window.onload链接外部js文件能不能写两次以上?即每一个js文件都用一下window.onload

jquery $(document).ready() 与window.onload的区别

Javascript Service Worker onload 显示通知

jquery中focus()失效怎么解决