Autosuggest无法使用追加

时间:2016-07-13 19:34:36

标签: jquery autosuggest

我正在使用jquery autosuggest。 当我尝试添加新的输入字段时,它会添加输入文本框,但不能与autosuggest一起使用。 不知道我哪里出错了,我没有错。 我可以做些什么来使autosuggest与附加工作?

<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>

1 个答案:

答案 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>