<script type="text/javascript">
function deleteUser() {
           var flag = false;
           for (var i = 0; i < document.getElementsByName("checkbox2").length; i++) {
            if (document.getElementsByName("checkbox2")[i].checked) {
             flag = true;
            }  
           }
           if (!flag) {
            alert("请选择需要删除的用户!");
            return;
           }
           if (window.confirm("确认删除吗?")) {
            with (document.getElementById("checkbox2")) {
             method = "post";
             action = "deleteAll.action";
             submit();
            } 
           }
         } </script>
            .
            .
            .
            .
<!---->
<s:iterator value="#request.list" id="us">
      <tr>
        <td height="20" bgcolor="#FFFFFF"><div align="center">
          <input type="checkbox" name="checkbox2" id="checkbox2" />
        </div></td>
       
        <td height="20" bgcolor="#FFFFFF" class="STYLE6"><div align="center"><span class="STYLE19"><s:property value="#us.username"/></span></div></td>
        <td height="20" bgcolor="#FFFFFF" class="STYLE19"><div align="center"><s:property value="#us.type"/></div></td>
        <td height="20" bgcolor="#FFFFFF" class="STYLE19"><div align="center"><s:property value="#us.tel"/></div></td>
        <td height="20" bgcolor="#FFFFFF" class="STYLE19"><div align="center">192.168.0.124</div></td>
        <td height="20" bgcolor="#FFFFFF" class="STYLE19"><div align="center"><s:property value="#us.detail"/></div></td>
        <td height="20" bgcolor="#FFFFFF"><div align="center" class="STYLE21"><s:a href="deleteUser.action?user.id=%{#us.id}" onclick="return del();">删除</s:a> | 查看</div></td>
      </tr>
      </s:iterator>  
//删除方法
public boolean deleteAllUsers(Integer id){
String hql = "from User user where id = "+id;
List<User> list = (List<User>)this.getHibernateTemplate().find(hql);
if(list!=null){
this.getHibernateTemplate().deleteAll(list);
return true;
}else {
return false;
}
}    想通过使用js来批量删除,但由于checkbox中的id号都一样,所以不可能执行,希望大家能帮帮忙,本人对js不是很了解(可以通过选中的id来批量删除对象,但我不知道怎么删除)

解决方案 »

  1.   

    var _chkGrp = document.getElementsByName("checkbox2");
    var menus = "";
    for(var i = 1 ;i < _chkGrp.length; i++){
    if(_chkGrp[i].checked == true){
    menus = menus + _chkGrp[i].value;
    menus = menus + ",";
    }
    }
    menus为你选中的所有的id,以“,”链接
    把menus传给后台,用split(",")方法取得每一个id做删除操作
      

  2.   

    <input type="checkbox" name="checkbox2" id="checkbox2" />这里设置他value为us.id
      

  3.   

    如果用js: 
    <input type="checkbox" name="usId" id="checkbox2" value="#us.id"/>
    var arr=document.getElementsByName("usId");//这是一个数组,判断里面的是否选中(checked==true)了,把选中的id数组传到后台去,
    否则,直接用表单提交就行了
      

  4.   

    function check(aa){
    if(aa.checked){
    var ids=document.getElementById("ids").value;
    document.getElementById("ids").value=ids+aa.value+",";

    }else{
    var ids=document.getElementById("ids").value;
    document.getElementById("ids").value=ids.replace(aa.value+",","");
    }
    if(document.getElementById("ids").value!=""){
    document.getElementById("tijiao").disabled=false;
    }
    }
    <s:hidden name="ids" id="ids"/>
     <s:iterator value="listBaseProcessFlowD" status="v" >
     <tr>
     <td>
     <INPUT TYPE="checkbox" NAME="id"  value="<s:property value="id"/>" onclick="check(this)"/>
     </td>

     </tr>
     </s:iterator>
      

  5.   

    function doDeleteAll(){
       var chks=document.getElementsByName("checkbox2");
       var ids=[];var count=0;
       for(var i=0;i<chks.length;i++){
          if(chks[i].checked){
            ids.push(chks[i].value);
            count+=1; 
      }
      if(count==0){
        alert("请选择记录");
      }else if(confirm("您选中了【"+count+"】记录,确定删除?")){
        var url="deleteAll.action?ids="+ids;
        window.location=url;
      }
    }
      

  6.   

    拿去用...........
    注意你要在action类里加入 int[] checkid ;set get 方法<script type="text/javascript">
    function remove(){
        var checkid = name('checkid');
        if (checkedCount(checkid) == 0) {
    alert('请选择要删除的数据!');
    return;
    }
    if(!window.confirm('你确定要删除吗?')){
       return;
            }
        document.forms[0].action = "commentRemove.do";
        document.forms[0].submit();
    }

    </script><s:form action="commentList.do" method="post" theme="simple" validate="false">
    <li><input type="button" value="删除" onclick="javascript:remove();" /></li> <table width="100%" border="0" cellspacing="0" cellpadding="0" style="table-layout:fixed;" >
    <tr>
        <td width="5%" align="center" valign="top"><span><input name="checkallname" id="checkallid" type="checkbox" onclick="javascript:checkAllBox();"></span></td>
    <td align="center" width="15%"><span>资源标题</span></td>
    <td align="center" width="10%"><span>操作</span></td>
    </tr>
    <s:iterator id="list" value="feedbackList.list">
    <tr>
    <td><input name="checkid" id="checkid" type="checkbox" value="<s:property value='#list.feedId'/>" /></td>
    <td><s:property value='#list.gatherRes.passname' />&nbsp;</td>
    <td><a href="javascript:if(window.confirm('你确定要删除吗?')){window.location='commentRemove.do?checkid=<s:property value='#list.feedId'/>';}">删除</a>&nbsp;</td>
    </tr>
    </s:iterator>
    </table>
    </s:form>
      

  7.   

    <input type="checkbox" name="checkbox2" id="<s:property value='id'/>" />
      

  8.   

    楼主你那个function 函数就做了 一判断 没读取数据删除