首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Select2 4.0多选框和占位符显示带有选项的空白项目

Select2 4.0多选框和占位符显示带有选项的空白项目
EN

Stack Overflow用户
提问于 2015-09-20 09:00:48
回答 1查看 704关注 0票数 0

我想要显示一个使用占位符的多选框(没什么特别的)。我在列表中添加了一个空白项,这样就可以按预期显示占位符。

代码语言:javascript
运行
复制
<select id="county_id" name="county_id" multiple="" tabindex="-1"     class="select2-hidden-accessible" aria-hidden="true">
<option value="" selected="selected"></option>
<option value="1">Adams</option>
<option value="2">Ashland</option>
<option value="3">Barron</option>

但是当我在列表中选择一个项目时,一个空白框(第一个空白选项)显示为第一个选择,就在我选择的项目之前。注意下面的第一个列表项:

代码语言:javascript
运行
复制
<span class="select2-selection select2-selection--multiple" role="combobox" aria-autocomplete="list" aria-haspopup="true" aria-expanded="false" tabindex="0">
<ul class="select2-selection__rendered">
<span class="select2-selection__clear">×</span>
<li class="select2-selection__choice" title=""><span class="select2-selection__choice__remove" role="presentation">×</span></li>
<li class="select2-selection__choice" title="Kenosha"><span class="select2-selection__choice__remove" role="presentation">×</span>Kenosha</li>

如果我没有在列表前面加上空白选项,那么占位符就不起作用了,默认情况下第一个列表项是选中的。

select2站点上最接近的示例使用了选项组(my list没有),并且似乎没有空白选项。我不记得在v3.5x中遇到过这个问题。除了占位符之外,我没有设置任何选项。我能做错什么呢?我怎样才能摆脱这个额外的空白选择?

EN

回答 1

Stack Overflow用户

发布于 2016-02-11 02:25:47

你有没有碰巧在用Formtastic?我在使用Formtastic时遇到了这个问题。如果不是,也许这可以帮助你找到正确的方向。我必须将:include_blank => false传递到我的表单中以删除空白元素。docs:prompt – by default, all select inputs will have a blank option at the top of the list. You can add a prompt with the :prompt option, or disable the blank option with :include_blank => false.可能是类似于这个的东西?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32674729

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档