Dropdownlist text is invisible in IE8

蹲街弑〆低调 提交于 2020-01-04 17:02:11

问题


For some reason my DDL options are all invisible in IE8. They're clearly there since the list has 127 options but the text is invisible. In Firefox everything shows up fine. I even tried putting an inline style on the select with the color set to black with !Important. When I inspect the DDL with Firebug it doesn't show it inheriting any styles, only what I've put inline.

I added var to the first line in the loop in case it was some kind of pass by reference issue, hoping that var would essentially create a new variable each time through the loop and not end up with a single instance. That didn't work either and from what I've read using var a second time on a variable in javascript does not cause it to become a new variable.

I'm populating the drop downs from an array:

var option = document.createElement("option");
option.textContent = "Select...";
option.value = 0;
departmentDropDownList.appendChild(option);

for (var i = 0; i < departments.length; i++)
{
    var option = document.createElement("option");
    option.textContent = departments[i][1];
    option.value = departments[i][0];
    departmentDropDownList.appendChild(option);
}

回答1:


IE8 does not support the textContent property. You have to shim for it and use innerText instead.

option.textContent = option.innerText = departments[i][1];


来源:https://stackoverflow.com/questions/16678419/dropdownlist-text-is-invisible-in-ie8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!