简体   繁体   English

jQuery:.focus()上的太多递归

[英]jQuery: too much recursion on .focus()

I am using the jQuery .focus() method to focus on an element through a remote script in asp.net. 我正在使用jQuery .focus()方法通过asp.net中的远程脚本来关注某个元素。 I am getting an error about too much recursion. 我收到有关过多递归的错误。

What am I doing wrong? 我究竟做错了什么?

asp.net code : asp.net代码:

Response.Write("<script>$('#ledger_name').focus();</script>");

html html

<input type="text" id="account_name" name="account_name" />

js for auto complete 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 ui jQuery UI

<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js" type="text/javascript"></script>

it's giving an error in jquery-ui.min.js file on calling $('#ledger_name').focus(); 调用$('#ledger_name').focus();在jquery-ui.min.js文件中给出错误$('#ledger_name').focus(); in autocomplete 自动完成

To have textbox with id of "ledger_name" focused upon page load, just add this JavaScript in your .aspx page: 要使ID为“ ledger_name”的文本框专注于页面加载,只需在.aspx页面中添加以下JavaScript:

<script type="text/javascript">
$(document).ready(function() {
    $("#ledger_name").focus();
});
</script>

No need to do that from the code behind. 无需从后面的代码中执行此操作。

Probably focusing it also triggers the autocomplete, so you can't focus it from within the autocomplete itself. 聚焦可能还会触发自动完成功能,因此您不能从自动完成本身内部进行聚焦。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM