jQuery加载函数后,jQuery UI自动完成功能不起作用

jQuery UI autocomplete is not working after jQuery load function

本文关键字:jQuery 成功 功能 不起作用 UI 加载 函数      更新时间:2024-05-12

我正在尝试使用jQuery UI自动完成函数,它非常有效,直到我用jQuery load()函数替换数据。在这之后,一切都不起作用——一片寂静。

我的html代码如下:

<div class="ui-widget">
         <label for="search">Search: </label>
         <input id="search">
</div>

我的js代码:

function enableAutocomplete(){
$( "#search" ).autocomplete({
    source: function( request, response ) {
        $.getJSON( "/Controller/search", {
            term: request.term
        }, response );
    },
    minLength: 2,
    select: function( event, ui ) {
        (...something going on here, doesn't matter...)
    }
});
}

}

load()成功返回后,我调用enableAutocomplete()将自动完成事件与我选择的元素再次绑定。我在这个论坛的某个地方读到,我应该这么做。但从那时起,什么都没发生。键入后永远不会调用自动完成。我在控制台中调试了它,并将所有内容记录在时间表中(Chrome开发工具),就像我说的那样,这里完全安静。有人知道吗,为什么??

你能试试这个吗

    function _debugResponse(respData,txt,xhr){console.log('Debug server response'); console.log(respData);}
function enableAutocomplete() {
  console.log('enableAutocomplete called');
  $("#search").autocomplete({
    source:    function (request, response) {
     console.log('autocomplete.source method called');
     $.getJSON("/Controller/search", { term: request.term }, _debugResponse );
    },
    minLength: 2,
    select:    function (event, ui) { console.log(event) }
  });
}                            
enableAutocomplete();

然后在开发控制台上发布你得到了什么?