[英]Select text box on page load jQuery
I have the following code which uses JavaScript to select a text box when the page loads. 我有以下代码,该代码在页面加载时使用JavaScript选择一个文本框。 I have included a copy of my code below. 我在下面提供了我的代码的副本。 My question is how can this be done in jQuery? 我的问题是如何在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 在此先感谢Callum
You also can use HTML5: 您还可以使用HTML5:
<input type="text" autofocus>
Reference: http://www.w3schools.com/html5/att_button_autofocus.asp 参考: http : //www.w3schools.com/html5/att_button_autofocus.asp
Cross Browser Compatibility: http://caniuse.com/#feat=autofocus 跨浏览器兼容性: http : //caniuse.com/#feat=autofocus
$(document).ready(function(){
$('#query').focus()
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.