json數據
[{"inherit":6,"majorID":7,"majorName":"交通工程系"},{"inherit":6,"majorID":9,"majorName":"交通運輸工程研究所"},{"inherit":6,"majorID":8,"majorName":"交通運輸系"}]
s:select
<s:select tabindex="-1"
list="#request.majorList" name="major" id="major"
listKey="majorID" listValue="majorName" value="#request.user.major"
headerKey="" headerValue="--請選擇--"
cssClass="chzn-select"
>
</s:select>
js應該怎麼寫
var d=[{"inherit":6,"majorID":7,"majorName":"交通工程系"},{"inherit":6,"majorID":9,"majorName":"交通運輸工程研究所"},{"inherit":6,"majorID":8,"majorName":"交通運輸系"}];
var sel=document.getElementById('major');
sel.options.length=0;//清空原來的項,如果不想清空去掉這句
for(var i=0;i<d.length;i++)
sel.options.add(new Option(d[i].majorName),d[i].majorID));