我正在使用带有 optgroups 的选择在移动设备上进行一些导航。我使用 optgroup 的标签来指示它所属的部分 - 然后使用选项本身来指定子部分。
The problem is that in pretty much every browser I come across doesn't show the optgroup when the select is not in focus. 我通过编写以下 jQuery 解决了这个问题:
$(".Nav-Interior-Mobile select option:selected").each( function() {
pageGroupLabel = $(this).parent('optgroup').attr('label');
pageItemLabel = $(this).text();
$(this).text(pageGroupLabel + " > " + pageItemLabel);
});
$('.Nav-Interior-Mobile select').focus( function() {
$(this).find('option:selected').text(pageItemLabel);
});
$('.Nav-Interior-Mobile select').blur( function() {
$(this).find('option:selected').text(pageGroupLabel + " > " + pageItemLabel);
});
这似乎适用于除 iOS 之外的所有应用程序。在 iOS 中,用于更改选择的 UI 不会反映用于焦点的新文本。我可以看到 Apple 用户界面上方的实际选择发生了变化——但他们的用户界面根本没有变化。
任何人都知道如何做到这一点?
模糊时它在这里工作:
并且在专注时无法工作(他们的 UI 应该只是说“Web”时仍然有“Branding > Web”):
这绝对是一个错误 - 如果您向下滚动然后在列表中备份 - 然后文本会更改 - 奇怪。