在 iOS 6.x (iPad) 上使用 JS 选择/取消选择下拉选项 [英] Select / deselect dropdown option with JS on iOS 6.x (iPad)

查看:90
本文介绍了在 iOS 6.x (iPad) 上使用 JS 选择/取消选择下拉选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 html <select> 标签创建动态 drodown,其属性为 multiple 并且默认选择第一个选项:

I'm creating dynamic drodown using html <select> tag with attribute multiple and first option selected by default:

<select multiple="multiple" size="1">  
    <option value="" selected="selected">All</option>  
    <option value="1">One</option>  
    <option value="2">Two</option>  
</select>

例如,用户点击选项One,然后假设的行为是取消选择All 选项并选择One 选项.

User taps option One for instance and then supposed behaviour is to deselect the All option and select the One option.

当 iPad 浏览器为下拉菜单打开本机 UI 时,我能够从下拉控件中捕获触摸事件(来自我的插件的代码片段):

When iPad browser open native UI for dropdown I am able to catch touch events from dropdown control (code snippets from my plugin):

this.$el.on('change', this.selectOption, this);

并通过以下方式操作选项以取消选择它们:

and manipulate options to deselect them in the way below:

selectOption: function(e){
    var opts = element.find('option');  
    opts.each(function(idx, opt){  
        $(opt).prop('selected', false);  
    });  
}

问题

选项属性已正确设置为 false 但在 iPad 的下拉 UI 中,所选选项的视觉效果保持不变 - 这可能会使用户感到困惑.
在点击下拉列表中的完成按钮后,UI 中的更改会应用.下一次打开显示取消选择的所有选项,这很好,但有点晚了;-)

The problem

Option properties are set to false properly BUT visually in iPad's dropdown UI selected options remain unchanged - which may confuse user.
The changes in UI are applied after Done button in dropdown is tapped. Next opening shows all options deselected which is OK but little bit late ;-).

是否可以通过用户点击一个选项而另一个在原生 iPad 下拉菜单中实时取消选择的方式来选择/取消选择选项?

Is this possible to select/deselect options in the way where user taps one option and the other one is being deseleted realtime in native iPad dropdown?

推荐答案

当我们在 IOS 中触发

发送“验证码”获取 | 15天全站免登陆