前台的控件
<input type='checkbox' name='isSelect' value='"+data[i].id+"' ></input></td>";
绑定按钮:
<input type="button" onclick="delEdu()" value="Delete" style="color:#95a5a6; border-radius:5px; vertical-align:middle;height:30px; 60px; "/>
js响应函数
function delEdu(){ var obj=document.getElementsByName('isSelect'); var s1="Select:"; var ids=''; for(var i=0; i<obj.length; i++){ if(obj[i].checked) ids=ids+obj[i].value+","; //如果选中,将value添加到变量s中 } if(ids==''){
alert("Please choose one!"); } else{ $.get("/portal/edu/delEduList?ids="+ids,function(data){ if("success"==data.result){ // alert("Delete Done!"); window.location.reload(); //load(pn,delFlag); } else{ alert("Error!"); } }); } }
后台controller:
@RequestMapping("/delEduList") public void delEduList(Long[] ids,HttpServletResponse response){ String result = "{"result":"success"}"; List<Education> edulistEducations = eduService.getByIds(ids); for(Education edu:edulistEducations){ eduService.delete(edu.getId()); } PrintWriter out = null; response.setContentType("application/json"); try { out=response.getWriter(); out.write(result); } catch (IOException e) { e.printStackTrace(); } }