开发者

The fastest way to set the focus on a textfield

开发者 https://www.devze.com 2023-02-23 15:55 出处:网络
what is the fastest (the really fastest) way to set the focus on a textfield? My page looks like <html>

what is the fastest (the really fastest) way to set the focus on a textfield?

My page looks like

<html>
 <head> ... </head>

  <body>

    ... content ...  

    <input type="text" id="ct_one" name="ct_pet[]" value="" />

    ... content ...

   <script&g开发者_开发知识库t; ... load jquery and jquery_ui ... </script>

  </body>

</html>

Thanks in advance!

Peter


You can put a script right after the element, that sets focus to it. That would set focus at the earliest possible moment, i.e. right after the element is created.

<input type="text" id="ct_one" name="ct_pet[]" value="" />

<script type="text/javascript">
document.getElementById('ct_one').focus();
</script>


Assign value 0 to attribute tabindex for your input field.

http://www.w3.org/TR/html4/interact/forms.html#adef-tabindex


the accepted answer here seems to be "the really fastest" :)

Set input field focus on start typing

JSFiddle example

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号