我正在使用 jQuery .focus()
方法通过 asp.net 中的远程脚本将焦点集中在某个元素上。我收到有关递归过多的错误。
我做错了什么?
asp.net 代码:
Response.Write("<script>$('#ledger_name').focus();</script>");
html
<input type="text" id="account_name" name="account_name" />
js自动完成
$("#account_name").autocomplete({
source: account_master,
minLength: 1,
minChars: 0,
width: 350,
mustMatch: 0,
selectFirst: true,
matchContains: false,
autoFocus: true,
autoFill: false,
change: function (event, ui) {
if (!ui.item) {
$(this).val('');
}
},
select: function (event, ui) {
$("#account_name").val(ui.item.label);
$("#account_name_code").val(ui.item.id);
$("#account_name_parent").val(ui.item.parent);
//$('#ledger_name').focus();
return true;
}
});
jquery 用户界面
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js" type="text/javascript"></script>
在自动完成中调用 $('#ledger_name').focus();
时,jquery-ui.min.js 文件中出现错误
最佳答案
要让 id 为“ledger_name”的文本框专注于页面加载,只需在您的 .aspx 页面中添加此 JavaScript:
<script type="text/javascript">
$(document).ready(function() {
$("#ledger_name").focus();
});
</script>
不需要从后面的代码中执行此操作。
聚焦它可能也会触发自动完成,因此您无法从自动完成本身内部聚焦它。
关于javascript - jQuery:.focus() 上的递归过多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13930166/