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

来源:互联网 发布:cpi数据查询 编辑:程序博客网 时间:2024/05/17 06:48
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都能测试成功,希望以后你可以用上。

 
原创粉丝点击