您的位置:首页 > 运维架构

将option添加到select框

2016-07-13 18:02 253 查看
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框
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: