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