jQuery批量操作

1:html文件

<li><aclass="add"href="javascript:void(0);"id="deleteAll"name="deleteAll">批量删除</a></li>

表头:<thwidth="5%">&nbsp;<inputtype="checkbox"name="allass"value="0"id="selectAll"/>&nbsp;</th>

循环取值:

<td><inputtype="checkbox"name="dels"id="${item.menuId}"value="${item.menuId}"/></td>

2:js中添加

$(document).ready(function(){

$("#selectAll").click(function(){

varstat=$("input:checkbox").attr("checked");

if(stat=='checked'){

$("input[name='dels']").each(function(){

this.checked=true;

});

}else{

$("input[name='dels']").each(function(){this.checked=false;});

}

});

});

$("#deleteAll").click(function(){

varstr=[];

$("input").each(function(){

if($(this).attr("checked")){

str.push($(this).val());

}

});

if(str.length==0){

alert('至少选择一个进行删除');

return;

}

if(confirm("确定删除吗?")){

$.post("appMenuDeleteAll.do","ids="+str+"&&validFlag=0",function(data){

location='appMenuList.do';

});

}

});

});

3:后台Controller写对应的方法

@RequestMapping("/appMenuDeleteAll.do")

publicStringappMenuDeleteAll(HttpServletRequestrequest,

HttpServletResponseresponse,ModelMapmodel)throwsException{

Stringid=request.getParameter("ids");

StringvalidFlag=request.getParameter("validFlag");

AppMenuappMenu=newAppMenu();

List<String>ids=newArrayList<String>();

String[]strs=StringUtils.split(id,",");

ids=Arrays.asList(strs);

appMenu.setList(ids);

appMenu.setValidFlag(Integer.parseInt(validFlag));

this.appMenuService.appMenuDeleteAll(appMenu);

returnnull;

}

相关推荐