选项添加到< select>在iPhone上的列表框中不可见 [英] Options added to a <select> are invisible in the list box on iPhone

查看:130
本文介绍了选项添加到< select>在iPhone上的列表框中不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个HTML列表框,并且使用javascript添加选项 - 在PC上的任何浏览器都没有问题 - Mozilla,Chrome,IE,Opera,Safari。但是,在iPhone上执行时,添加的选项在列表框中是不可见的 - 仅显示 - (0项),直到您点击列表框,然后看到添加的选项,就好像您正在点击常规的选择项目一样,点击它只有在该选项可见之后。我希望自己清楚了...

功能如下:用户填充文本框中的文本(tb),单击添加按钮(btn),选项被创建并显示在列表框中(lstbx)



以下是代码:

 < input type =textid =tb> 

< select id =lstbxmultiple =multiple>< / select>

< input type =buttonid =btnonclick =add_option(lstbx,form.tb,form.btn)>


函数add_option(lstbx,tb,btn){
var option = document.createElement(option);
if(tb.value!=){
option.text = tb.value;
option.value = tb.value;
lstbx.options.add(option);
tb.value =;}
}


解决方案

我已经成功地使用了options数组来做到这一点。因此,而不是创建HTML节点,使用JS API。另请注意,iOS上不支持多选框。

  var opt = new Option(tb.value,tb.value ,假,假); 
lstbx.options.add(opt);


I have an HTML listbox and I'm adding options using javascript - no problems in any browsers on PC - Mozilla, Chrome, IE, Opera, Safari. However, when performed on iPhone the added option is invisible in the listbox -shows only - (0 items) until you tap on the listbox and then you see the added option as if you were tapping on a regular "select" item, tap on it and only after that the option is visible. I hope I made myself clear enough...

The functionality is as follows: user fills text in textbox (tb), clicks the add button (btn), the option is created and displayed in the listbox (lstbx)

Here's the code:

<input type="text" id="tb">

<select id="lstbx" multiple="multiple"></select>

<input type="button" id="btn" onclick="add_option(lstbx, form.tb, form.btn)">


function add_option(lstbx, tb, btn) {
    var option = document.createElement("option");
        if (tb.value != "") {
            option.text = tb.value;
            option.value = tb.value;
            lstbx.options.add(option);
            tb.value = "";}         
    }

解决方案

I have successfully used the options array to do this. So instead of creating HTML nodes, use the JS API. Also be aware that multi select boxes are not supported on iOS.

var opt = new Option(tb.value, tb.value, false, false);
lstbx.options.add(opt);

这篇关于选项添加到&lt; select&gt;在iPhone上的列表框中不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆