bootstrap-tags-input adding a class to the generated input

[亡魂溺海] 提交于 2019-12-07 10:55:57

问题


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

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