【问题标题】:how to add a class to the input element generated by bootstrap-tagsinput如何向 bootstrap-tagsinput 生成的输入元素添加一个类
【发布时间】:2016-12-08 06:26:08
【问题描述】:

我尝试了the other post中建议的解决方案:

$("input[name='tags']").tagsinput('input').addClass('form-control');

但我得到了:

未捕获的类型错误:$(...).tagsinput(...).addClass 不是函数

我也绑了:

$("input[name='tags']").tagsinput({
    tagClass: 'form-control'
});

但还是无法添加form-control

有什么想法吗?谢谢。

【问题讨论】:

  • 你加了data-role="tagsinput.tagsinput('item')
  • 你能显示你的html吗?
  • @magreenberg 添加 data-role="tagsinput" 后,第一种方法现在可以使用。非常感谢。顺便说一句,知道为什么第二个不起作用吗?

标签: jquery bootstrap-tags-input


【解决方案1】:

我在Bootstrap Tags Input, assign class to tags based on ajax call也遇到了同样的问题。

我尝试了一种 hacky 方式。在 DOM 中,标签与类“标签”一起存储。 所以我使用简单的 jQuery 选择器来实现这一点:

 $("span.tag:contains("+event.item+")").addClass('label-success');

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-26
    • 1970-01-01
    • 2022-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-08
    • 2017-01-03
    相关资源
    最近更新 更多