iOS Safariselect多个选项进行单一select
我正在使用这个“空optgroup
”解决方法让iOS以可读的方式显示带有长文本的option
元素。 我正在使用下面的代码来testing这个解决scheme:
<p>Choose something:</p> <select> <option>Option A</option> <option>Some other option which is much longer than the first two options that has a distinguising feature at the end: B!</option> <option>Some other option which is much longer than the first two options that has a distinguising feature at the end: C!</option> <option>Option D</option> <option>Option E</option> <option>Option F</option> <option>Option G</option> <optgroup label=""></optgroup> </select>
optgroup { display: none; }
它确实使iOS Safari显示了长的选项,使得它们可以再次区分,但是它打开了另一个问题,即多个项目似乎被选中,即使它是单个select下拉菜单。
重现:
- 在完全更新的iPhone 4S上打开这个jsFiddle的全屏效果 ;
- 点击
select
打开它。
请注意,现在select了“选项A”。
- 在本机下拉控件中向下滚动,直到“选项A”不再可见。
- 点击select“选项E”。
- 向后滚动一下。
最终的结果是,似乎select了两个选项:
预期的结果显然是只有“E”被选中。
我该如何解决这个问题?
我发现这个问题没有optgroup
元素,当我以编程方式重新填充并selectcombobox中的默认项目,以响应另一个字段的变化。 我发现我只是先清除旧的select:
$("#time")[0].selectedIndex = -1 // this fixed it for me $("#time option").each(function () { if ($(this).val() == oldtime) { $(this).attr("selected", "selected"); return; } });
只有Safari有这个问题,这显然是一个单选列表可以有两个明显select的项目的错误。