select 框填充功能在 IE 9 中不起作用

select box population function not working in IE 9

我是网络开发世界的新手,到目前为止,在大多数情况下,一切都是桃子、奶油、水仙花和泰迪熊。在 Google Chrome 中大放异彩。

事实是,我工作的公司中的大多数人都会通过 IE-9 填写此表格。

我所有的 select 元素都在 IE-9 中损坏了。这些值有效并且创建了 option,但没有显示任何文本。

这是我的人口函数:

function fill_select(select, options)
{
    for(var i=0; i<options.length; i++) 
    {
      var opt= options[i];
      var el= document.createElement("option");
      el.textContent= opt;
      el.value= opt;
      select.add(el);
    }
}

我可以 fiddle 用其他方法来做到这一点,比如修改 innerHTML,但我想知道为什么它在 IE-9 中不起作用,所以我可以避免这些错误在未来。

仅供参考

所以解决方案是:

  • 添加选项
  • 然后添加文本和值
  • 最后,使用 .text
select.add(el);
el.text = opt;
el.value = opt;

很高兴对您有用! =)