首页 > 代码库 > ajax 遍历select 下拉框
ajax 遍历select 下拉框
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=http://www.mamicode.com/"" + jsonObj[j].name + "\">" + jsonObj[j].name + "</option>";
$("#type").html("<option value=http://www.mamicode.com/‘请选择‘ >请选择..."+ optionstring);
}
}
},
error: function (msg) {
alert("出错了!");
}
});
};
window.onload=addnotice; //页面加载完自动加载
</script>
ajax 遍历select 下拉框