码迷,mamicode.com
首页 > 其他好文 > 详细

将option添加到select框

时间:2016-07-13 22:38:14      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:

    var select=document.createElement("select");
    select.setAttribute("class","field size2");
    
    // 从隐藏的选择框里找选项
    var hideSelect=document.getElementById("hideSelect");
    for(var i=0;i<hideSelect.options.length;i++){
        var op=document.createElement("option");
        op.appendChild(document.createTextNode(hideSelect.options[i].text));// 设置文字
        op.setAttribute("value",hideSelect.options[i].value);// 设置值
            
        if(descId==hideSelect.options[i].value){
            op.selected = true;// 设置是否选中
        }
        
        select.appendChild(op);// 将option添加到select框
    }

 

将option添加到select框

标签:

原文地址:http://www.cnblogs.com/xiandedanteng/p/5667828.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!