Twitter bootstrap typeahead unable to add to dynamically created element

我只是一个虾纸丫 提交于 2019-12-01 19:18:53
Dustin L.

This solution requires no additional javascript. From https://stackoverflow.com/a/15094730

$("#element-that-will-contain-typeaheads").on("DOMNodeInserted", function () {
    $(this).find(".typeahead").typeahead();
});

I downloaded jquery.livequery.js to get the behavior I wanted:

$("#job_title").livequery("create", function() {
    $(this).typeahead({
        source: searchFunction,        
        onselect: function(obj) {            
        }
    });
});
var fx = {
    "init":function() {
        $("#id_of_an_element").typeahead({
            minLength:2,
            delay:1 ...
        })
    },
    "method2":function(){
        some content;
    }
}

Every time the element containing the typeahead is loaded into the DOM (eg. via AJAX success, call fx.init();

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!