如何将Bootstrap标签绑定到动态创建的元素? [英] How to bind Bootstrap Tags to dynamically created elements?
本文介绍了如何将Bootstrap标签绑定到动态创建的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在将Bootstrap标签绑定到输入字段时遇到问题,我认为这是因为输入字段是使用Ajax动态创建的.简直什么都没有开.
I'm having problems binding Bootstrap Tags to an input field an I think its because input field is dynamically created with ajax. Simply nothing is firing.
echo " <div class='tags-cont'>
<input value='".$tags."' class='tags' type='text' name='tags' data-role='tagsinput' placeholder='Add tags' />
</div>";
脚本在主体关闭标签之前嵌入:
Scrtipts are embeded before body closing tag:
<script src='scripts/plugins/bootstrap_tags/bootstrap-tagsinput.js' type='text/javascript'></script>
<link href='scripts/plugins/bootstrap_tags/bootstrap-tagsinput.css' rel='stylesheet' type='text/css' />
推荐答案
我明白了.对于将来会迷失于此的人:
I got it. For anyone who will stumble on this in the future:
删除:
data-role="tagsinput"
并实例化ajaxComplete上输入的标签:
And instantiate tagsinput on ajaxComplete:
$(document).ajaxComplete(function(){
$('.tags').tagsinput({
maxTags: 3
});
});
这篇关于如何将Bootstrap标签绑定到动态创建的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文