下拉列表一般通过ajax请求数据绑定
// 绑定新闻类型下拉 function news_type() { var news_type=$("#news_type").val(); $(".remove").remove(); $.ajax({ url : path + "/base/newsType", type : "POST", data : "json", success : function(data) { var html = \'\'; for (var i = 0; i < data.length; i++) { var checked=""; //如果id等于value,则选中 if(data[i].id==news_type){ checked="selected=\"selected\""; } html += " <option "+checked+" class=\'remove\' value=\'" + data[i].id + "\'>" + data[i].name + "</option>"; } $(".news_type").append(html); }, erro : function(e) { $.messager.alert("提示", "错误!", "error"); } }); }
前端代码
<select class=\'news_type\'></select>
后台返回的是List集合