element1 = document.createElement(“ select”);
var option1 = document.createElement("option");
option1.value="warm";
option1.innerHTML="warm";
element1.appendChild(option1);
var option2 = document.createElement("option");
option2.value="hot";
option2.innerHTML="hot";
element1.appendChild(option2);
最佳答案
您可以设置选项selected
属性
var element1 = document.createElement("select");
var option1 = document.createElement("option");
option1.value = "warm";
option1.innerHTML = "warm";
element1.appendChild(option1);
var option2 = document.createElement("option");
option2.value = "hot";
option2.innerHTML = "hot";
option2.selected = true; // LIKE THIS
element1.appendChild(option2);
FIDDLE