问题
I would like to add a class or other attributes to the input generated by bootstrap
<input type="text" value="">
$('input').tags-input();
generates:
<div class="bootstrap-tagsinput">
<input type="text" placeholder="add tags" style="width: 8em !important;">
</div>
I would like to add a class with: https://bootstrap-tagsinput.github.io/bootstrap-tagsinput/examples/
input
Returns the tagsinput's internal , which is used for adding tags. You could use this to add your own typeahead behaviour for example.
var $elt = $('input').tagsinput('input');
I don't seem to understand how would a class be added
Thank you
回答1:
Firstly, tagsinput is initialized like this
$("input").tagsinput();
The method tagsinput('input')
returns the input element to which other jQuery methods can be used like this
var $input = $("input").tagsinput('input');
$input.addClass('custom-class');
来源:https://stackoverflow.com/questions/31231752/bootstrap-tags-input-adding-a-class-to-the-generated-input