JS動(dòng)態(tài)添加與刪除select中的Option對(duì)象(示例代碼)
更新時(shí)間:2013年12月25日 09:42:28 作者:
本篇文章主要介紹了JS動(dòng)態(tài)添加與刪除select中的Option對(duì)象示例代碼。需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助
如下所示:
//動(dòng)態(tài)刪除select中的所有options:
function delAllOptions(){
document.getElementById("user_dm").options.length=0;
}
//動(dòng)態(tài)刪除select中的某一項(xiàng)option:
function delOneOption(index){
document.getElementById("user_dm").options.remove(index);
}
// 動(dòng)態(tài)添加select中的項(xiàng)option:
function addOneOption(){
//document.getElementById("user_dm").options.add(new Option(2,"mytest"));
var selectObj=document.getElementById("user_dm");
alert(selectObj.length);
selectObj.options[selectObj.length] = new Option("mytest", "2");
}
復(fù)制代碼 代碼如下:
//動(dòng)態(tài)刪除select中的所有options:
function delAllOptions(){
document.getElementById("user_dm").options.length=0;
}
//動(dòng)態(tài)刪除select中的某一項(xiàng)option:
function delOneOption(index){
document.getElementById("user_dm").options.remove(index);
}
// 動(dòng)態(tài)添加select中的項(xiàng)option:
function addOneOption(){
//document.getElementById("user_dm").options.add(new Option(2,"mytest"));
var selectObj=document.getElementById("user_dm");
alert(selectObj.length);
selectObj.options[selectObj.length] = new Option("mytest", "2");
}
您可能感興趣的文章:
- jquery動(dòng)態(tài)添加以及遍歷option并獲取特定樣式名稱的option方法
- 利用js給datalist或select動(dòng)態(tài)添加option選項(xiàng)的方法
- jQuery動(dòng)態(tài)產(chǎn)生select option下拉列表
- JQuery動(dòng)態(tài)添加Select的Option元素實(shí)現(xiàn)方法
- JS 通過(guò)系統(tǒng)時(shí)間限定動(dòng)態(tài)添加 select option的實(shí)例代碼
- JS & JQuery 動(dòng)態(tài)添加 select option
- js動(dòng)態(tài)改變select選擇變更option的index值示例
- 動(dòng)態(tài)添加option及createElement使用示例
- jquery動(dòng)態(tài)添加option示例
- 使用js對(duì)select動(dòng)態(tài)添加和刪除OPTION示例代碼
- JS動(dòng)態(tài)添加option和刪除option(附實(shí)例代碼)
- javascript 動(dòng)態(tài)設(shè)置已知select的option的value值的代碼
- javascript 動(dòng)態(tài)創(chuàng)建 Option選項(xiàng)
- js或jquery動(dòng)態(tài)輸出select option的實(shí)現(xiàn)代碼
相關(guān)文章
Vue2.0+ElementUI實(shí)現(xiàn)表格翻頁(yè)的實(shí)例
下面小編就為大家?guī)?lái)一篇Vue2.0+ElementUI實(shí)現(xiàn)表格翻頁(yè)的實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-10-10一個(gè)簡(jiǎn)單的JS鼠標(biāo)懸停特效具體方法
這個(gè)特效最終實(shí)現(xiàn)效果就是當(dāng)鼠標(biāo)移動(dòng)到鏈接上,文字會(huì)橫向移動(dòng)一定距離,貌似總有人喜歡這些花花草草。添加此效果方法很簡(jiǎn)單。2013-06-06在LayUI圖片上傳中,解決由跨域問(wèn)題引起的請(qǐng)求接口錯(cuò)誤的方法
今天小編就為大家分享一篇在LayUI圖片上傳中,解決由跨域問(wèn)題引起的請(qǐng)求接口錯(cuò)誤的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-09-09JavaScript中字符串與Unicode編碼互相轉(zhuǎn)換的實(shí)現(xiàn)方法
這篇文章主要介紹了JavaScript中字符串與Unicode編碼互相轉(zhuǎn)換的實(shí)現(xiàn)方法涉及JavaScript編碼、數(shù)據(jù)類型等的轉(zhuǎn)換技巧,需要的朋友可以參考下2015-12-12