2016-07-13 63 views
0

我正在使用jquery自動建議。 當我嘗試添加一個新的輸入字段時,它會添加輸入文本框,但不適用於自動提示。 不知道我哪裏錯了,我沒有錯誤。 我能做些什麼來使自動建議與追加工作?自動建議不能使用追加

<td><button class="add_field_button4">Add </button> </td> 
<div class="input_fields_wrap6"> 
     <input type="text" class="pets" value="#myArray[listCount]#"/> 
     <a class="remove_field">Remove</a> 
</div> 
<div class="input_fields_wrap3"> 

</div> 


<script type="text/javascript"> 

    $(document).ready(function() { 
    var max_fields3  = 30; //maximum input boxes allowed 
    var wrapper3   = $(".input_fields_wrap3"); //Fields wrapper 
    var add_button3  = $(".add_field_button3"); //Add button ID 
    var wrapper6   = $(".input_fields_wrap6"); //Fields wrapper 
    var x = 1; //initlal text box count 
    $(add_button3).click(function(e){ //on add input button click 
     e.preventDefault(); 
     if(x < max_fields3){ //max input box allowed 
      x++; //text box increment 
      $(wrapper3).append('<div><input type="text" class="pets" name="mytext[]" ><a href="#" class="remove_field">Removes</a></div>'); //add input box 


     } 
    }); 


    $(document).ready(function() { 
     $('.pets').autocomplete({ 
      source: function(query, response) { 
       $.ajax({ 
        url: "search.cfc?method=queryNames&returnformat=json", 
        dataType: "json", 
        data: { 
         searchPhrase: query.term 
        }, 
        success: function(result) { 
         response(result); 
        } 
       }); 
      } 
     }); 
    }); 
</script> 
+0

爲什麼你有兩個'$(文件)。就緒(函數(){...'? –

回答

1

嘗試:

<script type="text/javascript"> 

$(document).ready(function() { 
var max_fields3  = 30; //maximum input boxes allowed 
var wrapper3   = $(".input_fields_wrap3"); //Fields wrapper 
var add_button3  = $(".add_field_button3"); //Add button ID 
var wrapper6   = $(".input_fields_wrap6"); //Fields wrapper 
var x = 1; //initlal text box count 
$(add_button3).click(function(e){ //on add input button click 
    e.preventDefault(); 
    if(x < max_fields3){ //max input box allowed 
     x++; //text box increment 
     $(wrapper3).append('<div><input type="text" class="pets" name="mytext[]" ><a href="#" class="remove_field">Removes</a></div>'); //add input box 


    } 

    $('.pets').autocomplete({ 
     source: function(query, response) { 
      $.ajax({ 
       url: "search.cfc?method=queryNames&returnformat=json", 
       dataType: "json", 
       data: { 
        searchPhrase: query.term 
       }, 
       success: function(result) { 
        response(result); 
       } 
      }); 
     } 
    }); 
}); 
</script>