我在javascript中使用select标签创建了一些下拉框,现在我想将它转换为无序列表。我怎么能这样做?
这是我的代码
var myDiv = document.getElementById("myDiv");
//Create array of options to be added
var array = ["Volvo","Saab","Mercades","Audi"];
//Create and append select list
var selectList = document.createElement("select");
selectList.setAttribute("id", "mySelect");
myDiv.appendChild(selectList);
//Create and append the options
for (var i = 0; i < array.length; i++) {
var option = document.createElement("option");
option.setAttribute("value", array[i]);
option.text = array[i];
selectList.appendChild(option);
}
答案 0 :(得分:0)
尝试
var myDiv = document.getElementById("myDiv");
//Create array of options to be added
var array = ["Volvo","Saab","Mercades","Audi"];
//Create and append select list
var selectList = document.createElement("ol");
selectList.setAttribute("id", "mySelect");
myDiv.appendChild(selectList);
//Create and append the options
for (var i = 0; i < array.length; i++) {
var option = document.createElement("li");
option.innerHTML = array[i];
selectList.appendChild(option);
}