查看文章
 
JS对select动态添加options操作
2007年12月10日 星期一 23:06

<select id="ddlResourceType" onchange="getvalue(this)">
</select>

   动态删除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都能测试成功,希望以后你可以用上。
其实用标准的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);//获取文本
     }


类别:Ajax||添加到搜藏 |分享到i贴吧|浏览(479)|评论 (0)
 
最近读者:
 
网友评论:
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
     

   
帮助中心 | 空间客服 | 投诉中心 | 空间协议
©2012 Baidu