動態創建select
function createSelect(){
var mySelect = documentcreateElement_x("select");
mySelectid = "mySelect";
documentbodyappendChild(mySelect);
}
添加選項option
function addOption(){
//根據id查找對象
var obj=documentgetElementByIdx_x(mySelect);
//添加一個選項
objadd(new Option("文本""值"));
}
刪除所有選項option
function removeAll(){
var obj=documentgetElementByIdx_x(mySelect);
objoptionslength=;
}
刪除一個選項option
function removeOne(){
var obj=documentgetElementByIdx_x(mySelect);
//index要刪除選項的序號這裡取當前選中選項的序號
var index=objselectedIndex;
objoptionsremove(index);
}
獲得選項option的值
var obj=documentgetElementByIdx_x(mySelect);
var index=objselectedIndex; //序號取當前選中選項的序號
var val = objoptions[index]value;
獲得選項option的文本
var obj=documentgetElementByIdx_x(mySelect);
var index=objselectedIndex; //序號取當前選中選項的序號
var val = objoptions[index]text;
修改選項option
var obj=documentgetElementByIdx_x(mySelect);
var index=objselectedIndex; //序號取當前選中選項的序號
var val = objoptions[index]=new Option("新文本""新值");
刪除select
function removeSelect(){
var mySelect = documentgetElementByIdx_x("mySelect");
mySelectparentNoderemoveChild(mySelect);
}
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20153.html