[英]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.