我试图在加载页面后将注意力集中在表单的第一个输入上,但它不起作用!
$("#New").click(function() {
var area = $(this).attr("name");
$("#txtHint").hide().load("add_data.php?area=" + area, function(){
$(this).closest("form").find(':input:enabled:visible:first').focus();
}).fadeIn('slow');
//$(this).closest("form").find(':input:enabled:visible:first').focus();
});
我可以帮忙吗?
答案 0 :(得分:2)
假设你有这段代码:
<form id="formId">
<input type="text">
<input type="text">
<input type="text">
</form>
编写这个JQuery代码:
$("#formId input:text").first().focus();
包裹着
$(document).ready();
答案 1 :(得分:0)
您的代码重写为
$("#txtHint").hide().load("add_data.php?area=" + area, function(){
答案 2 :(得分:0)
尝试:
$(document).ready(function(){
$("#inputId").focus();
});