簡體   English   中英

選擇頁面上的文本框加載jQuery

[英]Select text box on page load jQuery

我有以下代碼,該代碼在頁面加載時使用JavaScript選擇一個文本框。 我在下面提供了我的代碼的副本。 我的問題是如何在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>

在此先感謝Callum

您還可以使用HTML5:

<input type="text" autofocus>

參考: http : //www.w3schools.com/html5/att_button_autofocus.asp

跨瀏覽器兼容性: http : //caniuse.com/#feat=autofocus

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM