前台代码
//动态追加类别下拉框
$(function() { $(".lb-text").focus(function(){ $(this).css("border-color","#e1e4e9") }) $(".btn-sure").click(function() { var lbtext = $(".lb-text").val(); if(lbtext==null||lbtext==""){ $(".lb-text").css("border-color","red") return false }else{ $(".lb-text").css("border-color","#e1e4e9") } var lbtype = $(".lb-type").val(); var lbid = $(".lb-id").val(); $('.default-val').text(lbtext); $.ajax({ timeout: 3000, url :"rjtd_lb_save.do", dataType : "json", type : "POST", data : { name : lbtext, type : lbtype, value : lbid},
async : false, success : function(data) { for (var i = 0; i < data.length; i++) { $('.Popup-box').hide(); $('.mask').hide(); $(".selector").append("<span>" + data[i].name+ "</span>") } } })})
})
后台代码
public void lbSave(CmsDictionary bean,HttpServletResponse response, ModelMap model) throws JSONException {
bean = manager.save(bean); JSONArray arr = new JSONArray(); JSONObject o; List<CmsDictionary> list = dictionaryMng.getList("sortware_genre"); for (CmsDictionary t : list) { o = new JSONObject(); o.put("id", t.getId()); o.put("name", t.getName()); arr.put(o); } ResponseUtils.renderJson(response, arr.toString()); }
效果图