我如何使用jquery中追加添加的类

时间:2015-06-23 09:24:42

标签: jquery

HTML:

div#exmkp p:nth-of-type(1) {
       margin-top : 10px;
    }

我确实会在html中使用同一类输入中的类添加更多输入到html JS:1:

<input class="typeahead" id="jj" type="text">
<a href='#' id="a">add input</a>

这是为类做自动完成 JS:2:

$("#a").each(function() {
$(this).on("click", function(){
     $('#jj).append('<input class="typeahead" type="text"');
});});

我如何使用class&#34; typeahead&#34;?

2 个答案:

答案 0 :(得分:1)

自动填充功能不支持事件委派。您需要将自动完成功能附加到新添加的元素。

append将在最后位置添加元素。您可以使用:last

中元素.ggg的集合中的#kkkk选择器来定位它
$('button').click(function(){
 $('#kkkk').append("<input type='text' class='ggg'/>");
 $('#kkkk .ggg:last').autocomplete({
   //BIND SOURCE HERE
 });
});

答案 1 :(得分:0)

 var mmm;
$.post('diagnoses.php',{},function(data){
              mmm = data;
    },"json")
    .done(function() {
                $('.ui-widget .auto').autocomplete({
                    source: mmm
                });
        });
$('#a').each(function(){
    $(this).click(function(){
    $('<input class="auto" type="text" placeholder="שם אבחנה">').appendTo('.ui-widget');
            $('.ui-widget .auto').autocomplete({
                 source: mmm
            });
    });
});