如何在动态html表javascript中选择选项值。没有从jsp页面中的数据库获取更新的选项值

时间:2014-01-13 07:54:46

标签: javascript html

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);

1 个答案:

答案 0 :(得分:2)

您可以设置选项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