您的位置:首页 > Web前端 > JQuery

jQuery批量操作

2013-12-19 16:03 211 查看
1:html文件
<li><a class="add" href="javascript:void(0);" id="deleteAll" name="deleteAll">批量删除</a></li>
表头:<th width="5%">  <input type="checkbox" name="allass" value="0" id="selectAll"/> </th>
循环取值:
<td ><input type="checkbox" name="dels" id="${item.menuId }" value="${item.menuId }"/></td>

2:js中添加

$(document).ready(function(){

$("#selectAll").click(function () {
var stat=$("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(){
var str=[];
$("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")
public String appMenuDeleteAll(HttpServletRequest request,
HttpServletResponse response, ModelMap model) throws Exception {
String id = request.getParameter("ids");
String validFlag = request.getParameter("validFlag");
AppMenu appMenu = new AppMenu();
List<String> ids = new ArrayList<String>();
String[] strs = StringUtils.split(id, ",");
ids = Arrays.asList(strs);
appMenu.setList(ids);
appMenu.setValidFlag(Integer.parseInt(validFlag));
this.appMenuService.appMenuDeleteAll(appMenu);
return null;
} 阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: