jquery auto complete for dynamically generated textboxes

后端 未结 5 2100
被撕碎了的回忆
被撕碎了的回忆 2020-12-05 11:45

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

i tested $(\"#some\")

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-05 12:02

    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.

    To resolve this, alter the code to read:

    $(function() {
    
        $("#button_newproduct").click(function() {
    
            var newItem = $("");
    
            $("#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.

提交回复
热议问题