【发布时间】:2015-09-20 01:00:48
【问题描述】:
我想显示一个使用占位符的多选框(没什么异常)。我在列表中添加了一个空白项,这样可以按预期显示占位符。
<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>
但是当我在列表中选择一个项目时,一个空白框(第一个空白选项)显示为第一个选择,就在我选择的项目之前。请注意下面的第一个列表项:
<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 站点上最接近的示例使用选项组(我的列表没有),并且似乎没有空白选项。我不记得在 v3.5x 中遇到过这个问题。除了占位符,我没有设置任何选项。我可能做错了什么?我怎样才能摆脱这个多余的空白选择?
【问题讨论】:
标签: jquery-select2-4