1. 程式人生 > >select下拉列表操作,如何兼容於IE和firefox

select下拉列表操作,如何兼容於IE和firefox

1.在為select 新增option時,如果用$('city').add(new Option(array[1],array[0])),只能兼容於ie;
   2.刪除 option 在 firefox 是 select.remove(selectedIndex),而不是 options.remove()
輸出 option[x].innerText 在 firefox 下用 options[x].textContent(firefox沒有innerText,就是用textContent 來替代的)
3.動態刪除select中的所有options:
       document.getElementById("ddlResourceType").options.length=0;

     動態刪除select中的某一項option:
       
var sObj=document.getElementById("ddlResourceType");
       sObj.removeChild(sObj.options[indx]);
   
動態新增select中的項option:
       document.getElementById("ddlResourceType").options.add(new Option(text,value));

   上面在IE和FireFox都能測試成功,希望以後你可以用上。