开发者

Select text box on page load jQuery

I have the following code which uses JavaScript to select a text box when the page loads. I have included a copy of my code below. My question is how can this be done in jQuery?

<!doctype html>
<html>
<head>

</head>
<body>

<input id="query">

   <script type="text/javascript">
      function box(query){
         document.getElementById('query').focus();
      }
      box('query');
   </script>

</body>
</html>
开发者_运维问答

Thanks in advance, Callum


You also can use HTML5:

<input type="text" autofocus>

Reference: http://www.w3schools.com/html5/att_button_autofocus.asp

Cross Browser Compatibility: http://caniuse.com/#feat=autofocus


$(document).ready(function(){
     $('#query').focus()
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜