javascript - 如何在 Bootstrap 多选中添加标签?

标签 javascript html twitter-bootstrap

这里是否有任何选项可以默认显示图像。

代码:

<select id="example-post" style="width:120px;!important;" class="footerSelect" name="multiselect[]" multiple="multiple">
    <option value="1">test</option>
    <option value="2">test1</option>
    <option value="3">test2 </option>             

</select>

 $('.multiselect-selected-text').text('Options');

enter image description here

这里我不想显示选项而是默认显示图像。

示例图片:

enter image description here

最佳答案

您只需在按钮中添加字形图标。

<span class="glyphicon glyphicon-pencil"></span>

完整示例:

<div class="dropdown">
  <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-expanded="true">
      <span class="glyphicon glyphicon-pencil"></span>
    <span class="caret"></span>
  </button>
  <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
    <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Action</a></li>
    <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Another action</a></li>
    <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Something else here</a></li>
  </ul>
</div>

JSFiddle

此外,您可以使用 jQuery 动态添加此类元素。

var span = $('<span></span>');
span.addClass('glyphicon');
span.addClass('glyphicon-pencil');
$('#foo').html(span);

关于javascript - 如何在 Bootstrap 多选中添加标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30636333/

相关文章:

javascript - 在子元素高度上更改父 div 高度

javascript - 如何让 navbar-collapse 与动画汉堡一起使用?

javascript - 异步函数不在 forEach 循环内等待

javascript - 使用 jeditable 和 autogrow 的问题

javascript - 菜单在不同浏览器尺寸下的意外结果

javascript - 对输入框中现有值的 HTML5 验证

html - 是否有必要使用媒体查询?

javascript - 全局变量保留旧值

javascript - 使用 canvas API 复制 CSS border-radius

html - div 垂直对齐的问题(Twitter Bootstrap 3)