jquery 接受checkbox批量刪除

/*刪除信息*/ javascript

$(function(){
$("#plsc").click(function(){
 var idlist="";
 var idCount=0;
 $(":checkbox[checked]").each(function(){
  idlist = idlist+$(this).val()+',';
  idCount++;
 });
 if(idCount==0){
  alert("請選擇刪除對象!");
  return ;
 }
   $(":checkbox[checked]").each(function(){
   $("tr[id="+$(this).val()+"]").remove();
 });
 
 $.ajax({
     type: "POST",
     url: "operate/deleteConsume!deleteConsume.action",
     data:"ids="+idlist,
     dataType:"json",
     async: false,  
     success: function(data){
     }
 });
}) java

}) ajax

頁面代碼 json

<sj:div id="bottom">
         <div id="bottom_01">
            <img src="<c:url value="/images/rt_name.jpg"/>"/>
         </div>
         <div id="bottom_02">
                <table width="100%" border="0" cellpadding="0" cellspacing="0">
                    <tr id="tr_content">
                      <th width="5%" height="40">ID</th>
                      <th width="15%" height="40">日期</th>
                      <th width="15%" height="40">分類</th>
                      <th width="15%" height="40">金額</th>
                      <th width="15%" height="40">帳戶</th>
                      <th width="30%" height="40">說明</th>
                      <th width="10%" height="40">操做</th>
                    </tr>
                    <s:if test="listConsume.isEmpty()">
                     <tr>
                       <td class="a" colspan="5"  width="100%" height="100%" align="center">
                          <img src="<c:url value="/images/nodata.png"/>"/>
                       </td>
                   </tr>
                    </s:if>
                    <s:else>
                        <tr class="table_index"></tr>
                     <s:iterator value="listConsume" id="ss" status="status">
                     <tr id="<s:property value="#ss.cid"/>"  onmouseover="changeBG(this)" onmouseout="changeBG1(this)">
                       <td  width="5%" height="40" align="center"><s:checkbox id="ids" name="ids" value="false" fieldValue="%{#ss.cid}"/>&nbsp;<s:property value="#status.count"/></td>
                       <td  width="15%" height="40" align="center"><s:property value="#ss.cdate"/></td>
                       <td  width="15%" height="40" align="center"><s:property value="#ss.cname"/></td>
                       <td  width="15%" height="40" align="center"><s:property value="#ss.cmoney"/></td>
                       <td  width="15%" height="40" align="center"><s:property value="#ss.atype"/></td>
                       <td  width="30%" height="40" align="center"><s:property value="#ss.cinstruction"/></td>
                       <td  width="10%" height="40" align="center">
                       <s:url var="url" action="">
                       <s:param name="" value=""/>
                     </s:url>
                  <s:a onclick="javascript:return confirm('是否刪除?,刪除後將不可恢復');" href="%{url}"><img alt="刪除"  src="<c:url value="/images/del.gif"/>"/></s:a>
                       </td>
                     </tr>
                    </s:iterator>
                    <tr>
                      <td></td>
                      <td>
                      <input type="button" id="checkboxAll" value="全選"/>
                      <input type="button" id="checkboxNo" value="全不選"/>
                      </td>
                      <td>
                      <input type="button" id="checkboxRev" value="反選"/>
                      <input type="button" id="plsc" onclick="javascript:return confirm('是否刪除?,刪除後將不可恢復');" value="批量刪除"/>
                      </td>
                      <td></td>
                    </tr>
                    </s:else>
                </table>
             </div>
  </sj:div>

 action 代碼 async

public String deleteConsume()throws Exception{
  //批量刪除支出信息
  String id[] = ids.split("\\,"); this

  for(int i=0;i<id.length;i++){
   this.iConsumeDao.delete(id[i]);
  }
  return SUCCESS;
 } url

struts.xml代碼 spa

<action name="deleteConsume" class="operateAction">    <result name="success" type="json">    </result>   </action>
相關文章
相關標籤/搜索