javascript对select标记进行清除和添加

清除

            for (var i = document.getElementById('Group').options.length - 1; i >= 0; i--) {
                document.getElementById('Group').options.remove(i);  
            }        

或者
  document.getElementById("Group").innerHTML = "";


添加
            for (var i = 0; i <= returnvalue.split('$').length - 1; i++) {
             var oOption = document.createElement("OPTION");
             document.getElementById('Group').options.add(oOption);
             oOption.innerText = returnvalue.split('$')[i].split('|')[0];
             oOption.value = returnvalue.split('$')[i].split('|')[1];
           
            }

 

PS 得到所选项的值和文字

 

document.getElementById('Group').options[document.getElementById('Group').selectedIndex].value

document.getElementById('Group').options[document.getElementById('Group').selectedIndex].innerText

 

posted on 2008-12-23 13:55  优雅小猪  阅读(524)  评论(0编辑  收藏  举报

导航