简体   繁体   English

jQuery自动完成的动态多条记录

[英]jQuery autocomplete for dynamic multiple records

I have the following HTML: 我有以下HTML:

<input name="data[Content][0][name]" type="text" class="content_name_1" id="content_name" >


<input name="data[Content][1][name]" type="text" class="content_name_2" id="content_name" >
                             ........


<input name="data[Content][n][name]" type="text" class="content_name_n" id="content_name" >

And the following jQuery-Code: 以及以下jQuery代码:

$('input[name="data[Content][0][name]"]').autocomplete({
        minLength: 0,
        source: function(request, response){
            $.ajax({
                url: '/contents/ajax_search/' + request.term,
                dataType: 'json',
                success: function(data){
                    response(data);
                }
            });
        }
    });

I create dynamicly HTML input fields and I want to link them with the autocomplete function, but i just can do this with one of them. 我动态创建HTML输入字段,并希望将它们与自动完成功能链接起来,但是我可以使用其中之一来做到这一点。 How can I solve this problem? 我怎么解决这个问题?

First method is to use multiple selectors, 第一种方法是使用多个选择器,

$('input[name="data[Content][0][name]"], input[name="data[Content][1][name], input[name="data[Content][2][name]"]"] ').autocomplete({
    });

Second method is to add class="common" in all your html boxes and use the class name as selector 第二种方法是在所有html框中添加class="common"并将类名用作选择器

$('.common').autocomplete({
    });

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

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