将option添加到select框

    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框
    }

 

posted @ 2016-07-13 18:02  逆火狂飙  阅读(435)  评论(0编辑  收藏  举报
生当作人杰 死亦为鬼雄 至今思项羽 不肯过江东