带有硬编码选项的组合框:
<select id="connectionname" class="connectionname" onchange="display();"><option>---Select---</option></select>
Javascript函数动态创建组合框选项:
function showDbDlg(){
var newar=new Array();
try{
var xhrArgs = {
url: "./ReadDBDetails",
content: {MODE:"DBNAMES"},
handleAs: "text",
load: function(response) {
var dbNames = response.trim();
dbNames=dbNames.substring(0,dbNames.length-1);
dbArray=dbNames.split(",");
/*var selectValue = document.getElementById("connectionname").value;
alert(selectValue);*/
document.getElementById("connectionname").options.length = 0;
for(var i=0;i<dbArray.length;i++){
var newValue = document.getElementById("connectionname").appendChild(document.createElement('option'));
newValue.text = dbArray[i];
}
formDialog.show();
},
error: function(error) {
alert("An unexpected error occurred: " + error);
}
};
var deferred = dojo.xhrPost(xhrArgs);
}catch(e){alert(e);}
}
document.getElementById("connectionname").options.length = 0;
答案 0 :(得分:3)
你试过这个吗?
document.getElementById("connectionname").options.length = 1;