将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框
    }
原文地址:https://www.cnblogs.com/heyang78/p/5667828.html