In iOS 8.0, Apple introduced a new bug in Safari on iPhone, which I think is very serious when using multiple <select>
elements. It's commonly used for example to select day of birth. To reproduce:
在iOS 8.0中,苹果在iPhone的Safari中引入了一个新的bug,我认为这在使用多个
-
Create a page with two
<select>
with multiple<option>
in each创建一个页面,其中包含两个 <选择> ,每个页面包含多个 <选项>
-
Open in Safari on iOS 8 on iPhone (The bug still exists in 8.0.2)
在iPhone上的iOS 8 Safari上打开(bug仍然存在于8.0.2)
-
Tap the first
<select>
点击第一个 <选择>
-
Choose the third option i.e. March
选择第三个选择,也就是三月
-
Notice that it doesn't update the
<select>
to what you chose (it does in iOS 7)注意,它不会将
-
Tap the second
<select>
element点击第二个 <选择> 元素
-
Notice the following:
请注意以下几点:
- The first
<select>
doesn't update - 第一个
- The second
<select>
shows 3 (which is the position of the first<select>
) - 第二个的位置)
- The picker below shows 1
- 下面的选择器显示了1
- The first
You can repeat this by alternating between tapping the first and second <select>
, and notice that it changes in the same pattern. This may appear randomly unless you know the pattern). It looks even more confusing if you also have a year-picker.
您可以交替使用第一个和第二个 <选择> ,并注意它在相同模式下的变化。这可能是随机出现,除非你知道模式。如果你也有一个选择年份的人,看起来会更让人困惑。
To try in your mobile device, try this jsfiddle: http://jsfiddle.net/m7baw590/6/embedded/result/
要尝试移动设备,请尝试以下jsfiddle: http://jsfiddle.net/m7baw590/6/embedded/result/
Also, the onchange="alert(this.value)"
reports an incorrect value (the same that is selected on the second <select>
element. You can see this here: http://jsfiddle.net/m7baw590/7/embedded/result/
另外,onchange=“alert(this.value)”报告了一个不正确的值(在第二个
These bugs does not occur if you click "Done" between each selection, or use the arrows to switch.
如果您在每个选择之间单击“Done”,或者使用箭头切换,则不会出现这些错误。
Is there any workaround for this?
有什么办法吗?
3 个解决方案
#1
7
I solved the problem this way:
我用这种方法解决了这个问题:
<select>
<option></option>
<option></option>
<option></option>
(...)
<optgroup disabled></optgroup>
</select>
Just added an empty <optgroup>
to the <select>
.
将空的
#2
10
I discovered another bug with select fields in iOS8 (Only on iPhone, iPad seems fine for example).
我在iOS8中发现了另一个选择字段的错误(仅在iPhone上,iPad似乎很好)。
http://jsbin.com/kuhogopafe/1
How to reproduce:
如何复制:
- Select 3 options
- 选择3个选项
- Unselect one option again
- 再次取消选择一个选项
- Result: instead of 2 selected options, only the last unselected option is reported as selected now
- 结果:现在只报告最后一个未选择的选项,而不是两个已选择的选项
#3
0
The only solution I found for iphone Safari is to disable all other select boxes onfocus and re-enable all onblur. This will force the user to push Done.
我为iphone Safari找到的唯一解决方案是禁用所有其他选择框onfocus并重新启用所有onblur。这将迫使用户完成。
#1
7
I solved the problem this way:
我用这种方法解决了这个问题:
<select>
<option></option>
<option></option>
<option></option>
(...)
<optgroup disabled></optgroup>
</select>
Just added an empty <optgroup>
to the <select>
.
将空的
#2
10
I discovered another bug with select fields in iOS8 (Only on iPhone, iPad seems fine for example).
我在iOS8中发现了另一个选择字段的错误(仅在iPhone上,iPad似乎很好)。
http://jsbin.com/kuhogopafe/1
How to reproduce:
如何复制:
- Select 3 options
- 选择3个选项
- Unselect one option again
- 再次取消选择一个选项
- Result: instead of 2 selected options, only the last unselected option is reported as selected now
- 结果:现在只报告最后一个未选择的选项,而不是两个已选择的选项
#3
0
The only solution I found for iphone Safari is to disable all other select boxes onfocus and re-enable all onblur. This will force the user to push Done.
我为iphone Safari找到的唯一解决方案是禁用所有其他选择框onfocus并重新启用所有onblur。这将迫使用户完成。