复选框checkbox实现批量删除

一、jsp页面

<script type="text/javascript" src="<%=path%>/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(function() {
//全选,反选
$('#chooseAll').click(function() {
var list = $('[name=ids]').length;
if ($('#chooseAll').attr("checked") == true) {
for ( var i = 0; i < list; i++) {
$('[name=ids]').attr("checked", "true");
}
} else if ($('#chooseAll').attr("checked") == false) {
$('[name=ids]').click();
}
});


//一、检查是否已选,jquery实现
$('[name=batchdelete]').click(function() {
var l=$("input[type=checkbox]:checked").size(); //size是选中的个数
if(l==0){
alert("未勾选要删除的对象");
}else{
alert("提交表单: "+l);
$('#form1').submit();
}

});


/*  二、 //检查是否已选js实现

var list = $('[name=ids]').length;
//alert("changdu "+list);
var a=0;

for( var n = 0; n < list; n++){
if($('[name=ids]')[n].checked==false){
a++;
alert("a: "+a);
alert("changdu "+list);
if(a===list){
alert("未勾选要删除的对象");
return false;
}  
}
if($('[name=ids]')[n].checked==true){
alert("勾选对象");
//parent.document.location.href="<%=path%>/counselorDeleteActionDo?id="+id;
return true;
}
}*/

});
</script>

<body>

<a href="mass_selectionpackage/mass_dataList.action">获得数据</a>
<form name="form1" id="form1" action="mass_selectionpackage/mass_batchDelete.action" method="post" >
<table>
<tr>
<th width="10%" colspan="1"></th>
<th width="15%">
序号
</th>
<th width="15%">
Id
</th>
<th width="30%">
Name
</th>
<th width="30%">
Time
</th>
</tr>
<s:iterator value="#request.imgList" id="imgs" status="rowstatus">
<tr>
 
<td >
<input type="checkbox" name="ids" id="ids" value="<s:property value="#imgs.id" />" />
</td>

<td><s:property value="#rowstatus.index+1"/></td>
<td>
<s:property value="#imgs.id" />
</td>
<td>
<s:property value="#imgs.imgname" />
</td>
<td>
<s:property value="#imgs.imgoperatingtime" />
</td>
<td>
<a
href="mass_selectionpackage/mass_deleteById.action?id=<s:property value="#imgs.id" />&content=<s:property value="#imgs.imgname" />&title=${title}">delete</a>
</td>
</tr>
</s:iterator>
<tr>
<td>
<input type="checkbox" name="chooseAll" id="chooseAll" />
</td>
<td>
ChooseAllOrUnchoose
</td>
<td>
<input name="batchdelete" type="button"  value="batchdelete">
</td>
</tr>
</table>
</form>

</body>


二、java类,action


package com.wm.mass.action;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.wm.bean.ActivityImg;


public class MassSelectionAction extends ActionSupport {
/**
* @author
*/
private static final long serialVersionUID = 8422741115018483046L;

private int id;
private int temcount=5;

private Object[] ids;//接收复选框中的id数组
private ActivityImg activityImg=new ActivityImg();
private List<ActivityImg> imgList1=new ArrayList<ActivityImg>();
private List<ActivityImg> imgList;
private boolean flag;

{
for (int i = 1; i < temcount; i++) {
activityImg.setId(i);
activityImg.setImgname("名称——"+i);
activityImg.setImgoperatingtime("时间——:"+i);
imgList1.add(activityImg);
}
}
public String dataList() {
imgList=this.imgList1;
return SUCCESS;
}

public String deleteById() throws UnsupportedEncodingException {

System.out.println("删除:"+getContent()+", id:"+getId());
temcount--;
return this.dataList();
}

/*
* 批量删除
*/
public String batchDelete() throws UnsupportedEncodingException {

for(int i=0;i<ids.length;i++){
 // employeeService.delete(ids[i]);
  System.out.println("删除:"+getContent()+", id:"+ids[i]);
 }
return this.dataList();
}
 
public List<ActivityImg> getImgList() {
return imgList;
}
public void setImgList(List<ActivityImg> imgList) {
this.imgList = imgList;
}
 
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}

public Object[] getIds() {
return ids;
}
public void setIds(Object[] ids) {
this.ids = ids;
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值