我有一个带有大表单的页面,我试图在页面加载时分配具有焦点的表单元素。它似乎起作用,因为光标位于选定的表单元素中,但是,焦点事件没有被触发。如果我最小化浏览器然后再次最大化它,焦点事件就会被触发,但不会在 jQuery(document).ready() 上触发。任何建议表示赞赏...
jQuery(document).ready(function()
{
console.log("call focus");
jQuery("#tbl_Employees").find(".employeeinfo:eq(" + IndexEmp + ")").find("tr#trSequence").find("td:eq(5)").children(":first").focus();
});
jQuery(":input").focus(function(e)
{
console.log("enter focus");
});
最佳答案
我认为你应该将 $(":input")
放在 ready
函数中,放在 $("#tbl_Employees")
之前>
jQuery(function() { // <-- Same exact thing as `jQuery(document).ready(function () {`, just much shorter. Welcome to jQuery
jQuery(':input').focus(function(e) {
console.log("enter focus");
});
console.log("call focus");
jQuery("#tbl_Employees").find(".employeeinfo:eq(" + IndexEmp + ")").find("tr#trSequence").find("td:eq(5)").children(":first").focus();
})
关于javascript - 从 jQuery(document).ready 调用时 focus() 不会触发 focus 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18894801/