html :<select id="type" > </select>
js代码:
<script type="text/javascript">
//动态绑定下拉框项
function addnotice() {
$.ajax({
url: "${pageContext.request.contextPath}/dictionary/jindex.action?sign=4", //后台返回json数据
type: "post",
dataType: "json",
contentType: "application/json",
traditional: true,
success: function (data) {
for (var i in data) {
var jsonObj =data[i];
var optionstring = "";
for (var j = 0; j < jsonObj.length; j++) {
optionstring += "<option value=\"" + jsonObj[j].name + "\">" + jsonObj[j].name + "</option>";
$("#type").html("<option value=‘请选择‘ >请选择...</option>"+ optionstring);
}
}
},
error: function (msg) {
alert("出错了!");
}
});
};
window.onload=addnotice; //页面加载完自动加载
</script>