How to bind Bootstrap Tags to dynamically created elements?

霸气de小男生 提交于 2019-12-11 11:34:51

问题


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

回答1:


I got it. For anyone who will stumble on this in the future:

Remove:

data-role="tagsinput"

And instantiate tagsinput on ajaxComplete:

$(document).ajaxComplete(function(){
        $('.tags').tagsinput({
            maxTags: 3
        });
    });


来源:https://stackoverflow.com/questions/24104930/how-to-bind-bootstrap-tags-to-dynamically-created-elements

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