twitter引导类型无法添加到动态创建的元素 [英] twitter bootstrap typeahead unable to add to dynamically created element

查看:133
本文介绍了twitter引导类型无法添加到动态创建的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法将twitter bootstrap的typeahead函数转换为$(body)。on()函数?

  $(#job_title)。typeahead({
source:searchFunction,
onselect:function(obj){
}
});

但是,如果我动态添加id =job_title的文本输入,上面的函数不会工作。是否有解决方法?

/ downloadsrel =nofollow> jquery.livequery.js 以获得我想要的行为:

  $ (#job_title)。livequery(create,function(){
$(this).typeahead({
source:searchFunction,
onselect:function(obj){
}
});
});


Is there a way to convert twitter bootstrap's typeahead function into a $("body").on() function? The following code works fine if the element exists on the page load.

$("#job_title").typeahead({
    source: searchFunction,        
    onselect: function(obj) {            
    }
});

But if I add the text input with id="job_title" dynamically, the above function doesn't work. Is there a workaround for this?

解决方案

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

$("#job_title").livequery("create", function() {
    $(this).typeahead({
        source: searchFunction,        
        onselect: function(obj) {            
        }
    });
});

这篇关于twitter引导类型无法添加到动态创建的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆