开发者

Select text box on page load jQuery

开发者 https://www.devze.com 2023-03-05 13:30 出处:网络
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?

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

精彩评论

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