jQuery的自动完成动态生成的文本框 [英] jquery auto complete for dynamically generated textboxes

查看:245
本文介绍了jQuery的自动完成动态生成的文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的jQuery,我工作一个网页,用动态生成所需的文本框上的自动完成设施。

i am new to jquery, i am working on a web page which needs generating text boxes dynamically with autocomplete facility.

我测试 $(#有些)自动完成(数据); 上的一些静态的内容,它的工作完美

i tested $("#some").autocomplete(data); on some static content, it worked perfectly.

然而,当我尝试相同的技术与它不工作动态生成的文本框!

however, when i try the same technique with dynamically generated text boxes it's not working!

我的code如下所示:

my code looks as follows:

$(function() {  

  $("#button_newproduct").click(function(){  
    $("#products_table > tbody").append(
      "<tr><td><input type='text'name='td_products["+counter+"]'/></td></tr>");
  });
  var data = "Core celectors cttributes craversing canipulation CSS cvents cffects cjax ctilities".split(" ");
  $('input[name^=td_products]').autocomplete(data);
});

感谢大家好我做了这个与UR帮助。

thanks guys i am done with this with ur help.

现在,另一个问题。我加载下面

now, another problem. i am loading the array(input to autocomplete) with a DWR call.as below

DwrService.populateProducts(someFunc);
function someFunc(result){
    autoProducts=result;
    input.autocomplete(result);
 }

这里的问题是,每次制作DWR调用数据库来获得阵!

here problem is everytime making a DWR call to DB to get the array!

有没有办法从DWR数组存储在一个全局变量?

is there any way to store the array from DWR in a global variable?

关于

推荐答案

主要的问题我觉得是,你所呼叫的click处理程序之外的自动完成。因此,自动完成被设置在页面加载时,而不是在单击按钮时。

The main issue i think is that you are calling the autocomplete outside of the click handler. So the autocompletion gets set up when the page loads, rather than when the button is clicked.

要解决此问题,修改code阅读:

To resolve this, alter the code to read:

$(function() {

    $("#button_newproduct").click(function() {

        var newItem = $("<tr><td><input type='text'name='td_products["+counter+"]'/></td></tr>");

        $("#products_table > tbody").append(newItem); 

        var data = "Core celectors cttributes craversing canipulation CSS cvents cffects cjax ctilities".split(" "); 
        newItem.find('input').autocomplete(data);

    });
});

现在自动完成正在对每一个新的项目设置,而不是一次,在开始。

Now the autocompletion is being set on each new item, rather than once, at the start.

这篇关于jQuery的自动完成动态生成的文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆