自动补全不使用ajax生成的文本框

时间:2021-11-12 03:17:49

In my page I am using ajax to generate/show a textbox after button click. I am using autocomplete functionality in this textbox, but autocomplete call is not firing off. I cannot see the autocomplete call in firebug when I try to enter anything in the textbox.

在我的页面中,我使用ajax在单击按钮后生成/显示文本框。我正在这个文本框中使用自动补全功能,但是自动补全调用并没有启动。当我试图在文本框中输入任何内容时,我看不到firebug中的自动补全调用。

But at the same time it is working fine in a plain test page which has a textbox (without ajax generation), so that means jQuery, autocomplete files are okay.

但是与此同时,它在一个具有文本框(没有ajax生成)的普通测试页面中运行良好,所以这意味着jQuery,自动完成的文件是可以的。

I am suspecting ajax generated textbox's ID should be called in autocomplete function in a different way. I have attached below what way I tried.

我怀疑ajax生成的文本框的ID应该以不同的方式在autocomplete函数中调用。我把我尝试过的方式写在下面。

<script>
    $(function(){  
        $("#orderingparty2").autocomplete("auto/findparty.cfm");
    })
</script>

2 个解决方案

#1


3  

Bind the code adding autocomplete to the ajax function which is generating the input box. Else you can trigger the autcomplete event on any event like onclick.

将添加自动完成的代码绑定到生成输入框的ajax函数。否则,您可以在任何事件(如onclick)上触发autcomplete事件。

$("#orderingparty2").live('click',function(event) 
{

$(this).autocomplete("auto/findparty.cfm");


});

#2


0  

You have to attach the autocomplete call in the ajax handler that appends the textbox, something like this:

您必须将自动完成调用附加到文本框的ajax处理程序中,如下所示:

$.ajax({  
   ... 
   success(function(...) {
      $('<input type="text">')             
         .attr(...)
         .css(...)
         .appendTo('#myForm')
         .autocomplete("auto/findparty.cfm");  
   })
   ...
});

#1


3  

Bind the code adding autocomplete to the ajax function which is generating the input box. Else you can trigger the autcomplete event on any event like onclick.

将添加自动完成的代码绑定到生成输入框的ajax函数。否则,您可以在任何事件(如onclick)上触发autcomplete事件。

$("#orderingparty2").live('click',function(event) 
{

$(this).autocomplete("auto/findparty.cfm");


});

#2


0  

You have to attach the autocomplete call in the ajax handler that appends the textbox, something like this:

您必须将自动完成调用附加到文本框的ajax处理程序中,如下所示:

$.ajax({  
   ... 
   success(function(...) {
      $('<input type="text">')             
         .attr(...)
         .css(...)
         .appendTo('#myForm')
         .autocomplete("auto/findparty.cfm");  
   })
   ...
});