[英]Select box options not visible in IE 8
I am using Javascript to create a <select>
box. 我正在使用Javascript创建一个
<select>
框。 It is working fine in Firefox and Chrome but in Internet Explorer the <option>
s are not visible. 它在Firefox和Chrome中运行良好,但在Internet Explorer中,
<option>
是不可见的。
HTML HTML
<select id="categroy_renew" name="categroy_renew" onchange="category_check()" style="width:310px; height:35px; padding:8px; margin-left:95px;">
<option value="0">Select Your Category</option>
</select>
Javascript 使用Javascript
var category_vals = document.getElementById("categroy_renew");
for(var i=0;i<data.length;i++){
category_vals.appendChild(new Option("PK-"+data[i].cat,data[i].cat));
}
}
I tried category_vals.innerHTML
- it not even displayed the default <option>
"Select your category", although it is present in HTML. 我尝试了
category_vals.innerHTML
- 它甚至没有显示默认的<option>
“选择你的类别”,尽管它存在于HTML中。
You can use add() function of javascript 你可以使用javascript的add()函数
var category_vals = document.getElementById("categroy_renew");
for(var i=0;i<data.length;i++){
var option = document.createElement("option");
option.text = "PK-"+data[i].cat,data[i].cat;
category_vals.add(option);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.