>
🎜> function createSelect(){
var mySelect = document.createElement_x("select");
mySelect.id = "mySelect";
🎜>
//依id找出對象,
var obj=document.getElementByIdx_x('mySelect')
;
;;
;
;
var obj=document.getElementByIdx_x('mySelect');var index=obj.selectedIndex; //序號,取目前選取選項的序號var val = obj.options[index].text;
7.修改選項option
var obj=document.getElementByIdx_x('mySelect');var index=obj.selectedIndex; //序號,取目前選取選項的序號var val = obj.options[index]=new Option ("新文字","新值");
8.刪除select複製程式碼 程式碼如下:function removeSelect(){var mySelect = document.getElementByIdx_x("mySelect");mySelect.parentNode.removeChild(mySelect); 程式碼如下:複製程式碼 程式碼如下:
複製程式碼
程式碼如下:
function watch_ini(){ // 致命
for(var i=0; i
var oOption=new Option(arguments[i],arguments[i ] ]);
document.getElementByIdx_x("MySelect")[i]=oOption;
}
}
function watch_add(f){ // 增加
o Option=new f .word.value,f.word.value);
f.keywords[f.keywords.length]=oOption;
}
整個實例完整程式碼如下:
渡//en">
javascript 選擇選項文字值
用一個創建字串一個數組方法:
複製程式碼
複製程式碼
程式碼如下:
作者最新文章
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31