我的代码在Safari和FF中正常工作,但在IE中,下拉列表为空。它只是空的。有任何想法吗?这是jquery-1.5。谢谢!通过javascript添加选择元素不起作用,即ie
var sel = document.createElement("select");
sel.setAttribute("id", key)
sel.setAttribute('name', key)
for (var option in ddHash[key]){
var optElement = document.createElement("option")
optElement.text = ddHash[key][option]
if (// some conditional){
optElement.selected = true
}
else {
optElement.selected = false
}
sel.appendChild(optElement)
}
如果你使用jQuery,为什么不使用jQuery方法(http://stackoverflow.com/questions/170986/what-is-the-best-way-to-add-options-to-a-选择从 - 一个阵列与 - jquery的)? – 2011-04-28 05:40:52