当前位置:编程文档 >> JSP >> JS对select动态添加options操作方法
首页

JS对select动态添加options操作方法

所属类别:JSP
推荐指数:★★☆
文档人气:30
本周人气:7
发布日期:2008-7-3
<select id=\"ddlResourceType\" onchange=\"getvalue(this)\">
</select>

    动态删除select中的所有options: 
       document.getElementById(\"ddlResourceType\").options.length=0; 

     动态删除select中的某一项option: 
       document.getElementById(\"ddlResourceType\").options.remove(indx);  

     动态添加select中的项option: 
       document.getElementById(\"ddlResourceType\").options.add(new Option(text,value)); 

     上面在IE和FireFox都能测试成功,希望以后你可以用上。 
其实用标准的DOM操作也可以,就是document.createElement,appendChild,removeChild之类的。 

取值方面
    function getvalue(obj)
     ...{
         var m=obj.options[obj.selectedIndex].value
         alert(m);//获取value
         var n=obj.options[obj.selectedIndex].text
         alert(n);//获取文本
     }

文档说明:

     

相关文档


读取评论列表……