0
我有一個組合框,它具有一些值,我也有一些值,我從組合框中選擇一個值並進行一些操作並返回選定的值(在會話中設置這些值)。現在我需要自動選擇組合框中會話的值。從動態創建的組合框中刪除重複的值
我按照下面的JavaScript和它工作正常,但它創建了一個重複的值,它是已在組合框中:
function addCombo() {
var reportID = '<%=reportid%>';
var reportName = '<%=reportname%>';
var textb = document.getElementById("reportnames");
var option = document.createElement("option");
option.text = reportName;
option.value = reportID;
option.selected='selected';
try {
textb.add(option, null); //Standard
}catch(error) {
textb.add(option); // IE only
}
textb.value = "";
}
誰能幫我鑑別?
這個鏈接可以幫助你:http://stackoverflow.com/questions/4590311/set-option-selected-attribute-from-dynamic-created-option – Anoop