问题
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