我在用着这个“空optgroup“ 解决方法 https://stackoverflow.com/a/19735870/419956让 iOS 显示option
以可读的方式包含长文本的元素。我正在使用以下代码来测试此解决方案:
<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; }
It does使 iOS Safari 显示包裹的长选项,以便再次区分它们,但这带来了另一个问题似乎选择了多个项目即使它是一个单一的选择下拉列表。
重现:
- Open 这个jsFiddle http://jsfiddle.net/1tpc33Lf/'s 全屏结果 https://jsfiddle.net/1tpc33Lf/embedded/result/在完全更新的 iPhone 4S 上;
- Tap the
select
打开它。
请注意,现在已选择“选项 A”。
- 在本机下拉控件中向下滚动,直到“选项 A”不再可见。
- 点击选择“选项E”。
- 向后滚动一点。
最终结果是似乎选择了两个选项:
预期的结果显然是只选择“E”。
我该如何解决这个问题?
我发现这个问题没有optgroup
元素,当我以编程方式重新填充并选择组合框中的默认项目时,以响应另一个字段的更改。我发现我只需要先清除旧的选择:
$("#time")[0].selectedIndex = -1 // this fixed it for me
$("#time option").each(function () {
if ($(this).val() == oldtime) {
$(this).attr("selected", "selected");
return;
}
});
只有Safari有这个问题,这显然是一个错误,单选列表可以有两个可见的选择项。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)