1. 程式人生 > >select下拉框之去掉重複

select下拉框之去掉重複

window.onload =function(){
select1();
select2();
     
}

function select1() {
   var opts = document.getElementById('add_stdevice_code').options;
   var obj = new Object(), index = 0;
   while (index < opts.length) {
       if (opts[index].text in obj) opts[index] = null;
       else {
           obj[opts[index].text] = opts[index].text;
           index++;
       }
   }
   obj = null;



function select2() {
   var opts = document.getElementById('add_stdevice_stcd').options;
   var obj = new Object(), index = 0;
   while (index < opts.length) {
       if (opts[index].text in obj) opts[index] = null;
       else {
           obj[opts[index].text] = opts[index].text;
           index++;
       }
   }
   obj = null;
}