3个回答
展开全部
我以前写的遍历json对象动态增加到select中,供参考。
//jopt: json对象
//selectobj: select对象 var selectobj = document.getElementById("selectid");
//<select id="selectid" name="selectid"></select>
//delimit: value和text间的分隔符,连接值value + delimit + text作为text
function add_json_selopt(jopt,selectobj,delimit)
{
var bb;
var cc;
var opt;
var undefined = "undefined";
if (jopt && typeof jopt === 'object') {
for(var aa in jopt){
if (typeof aa == 'function') continue;
bb = aa.toString(); //value
if (bb != undefined){
cc = bb + delimit + jopt[aa].toString(); //text
opt = new Option(cc,bb);
selectobj.options.add(opt);
}
}
}
}
//jopt: json对象
//selectobj: select对象 var selectobj = document.getElementById("selectid");
//<select id="selectid" name="selectid"></select>
//delimit: value和text间的分隔符,连接值value + delimit + text作为text
function add_json_selopt(jopt,selectobj,delimit)
{
var bb;
var cc;
var opt;
var undefined = "undefined";
if (jopt && typeof jopt === 'object') {
for(var aa in jopt){
if (typeof aa == 'function') continue;
bb = aa.toString(); //value
if (bb != undefined){
cc = bb + delimit + jopt[aa].toString(); //text
opt = new Option(cc,bb);
selectobj.options.add(opt);
}
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询