jquery复选框checkbox实现删除

来源:互联网 发布:学通java的24堂课 pdf 编辑:程序博客网 时间:2024/05/21 22:47

function deleteUser() { 
        //当时是想把内容以str+=""的方式 进行保存 ,但不行  
        //var str; 
        var array = new Array(); //用于保存 选中的那一条数据的ID  
        var flag; //判断是否一个未选  
        $("input[name='selectFlag']:checkbox").each(function() { //遍历所有的name为selectFlag的 checkbox 
                    if ($(this).attr("checked")) { //判断是否选中   
                        flag = true; //只要有一个被选择 设置为 true 
                    } 
                }) 
        if (flag) { 
            $("input[name='selectFlag']:checkbox").each(function() { //遍历所有的name为selectFlag的 checkbox 
                        if ($(this).attr("checked")) { //判断是否选中   
                            //alert($(this).val()); 
                            array.push($(this).val()); //将选中的值 添加到 array中 
                            //str+=$(this).val()+","; 
                        } 
                    }) 
            //将要集体删除的数据 传递给action处理  
            window.self.location = "deleteUser?info=" + array; 
        } else { 
            alert("请至少选择一个用户"); 
        } 
    } 

 

实例:

<%@ page language="java" pageEncoding="utf-8" %>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib uri="/ly-tags" prefix="lytag"%>
<div id="carplan_order_list" class="pageContent">
 <div class="panelBar">
    <ul class="toolBar">
     <li><a class="delete" onclick="selected_remove_libe('ids_pany_value')" id="ids_pany_value_delete" rel="ids_pany_value_delete" title="确定退出重排吗?"><span>退出重排</span></a></li>
   <%-- <li><a class="edit" href="${ctx}/dybcb/edit/{sid_user}" target="ajaxTodo" title="确认给该旅客发送短信?"><span>发送短信</span></a></li> --%>
   <li class="line">line</li>
   <span style="margin-left: 150px;color:blue; font-size:x-large;">车次旅客</span>
   <li class="line">line</li>
   <span style="margin-left: 90px;">目前人数:49</span><span id="showtotal_money"></span>
   <li class="line">line</li>
   <span style="margin-left: 50px; color: red;">接客起始时间:</span><span><fmt:formatDate value="${objEnt.DepartureTime }" pattern="yyyy-MM-dd HH:mm"/></span>
  </ul>
  </div>
 <div style="width: 100%; height: 153px; overflow: auto;">
 <table class="list" id="car_play_lieb_tableid"  width="97%">
  <thead>
  <tr>
  <th width="22"><input type="checkbox" group="ids_pany_value" class="checkboxCtrl"></th>
  <th width="50">定单号</th>
  <th width="80">旅客名称</th>
  <th width="55">同行人数</th>
  <th width="90">联系电话</th>
  <th width="90">宾馆名称</th>
  <th width="60">航班/火车</th>
  <th width="90">班次时间</th>
  <th width="60">费用(金额)</th>
  </tr>
 </thead>
 <tbody id="ccorderList">
 <c:forEach items="${mapEnt}" var="item" varStatus="stat">
    <tr target="sid_user" rel="${item.RID}">
    <td><input name="ids_pany_value" value="${item.RID}" type="checkbox"></td>
    <td>${item.RID}</td>
    <td>${item.PASSENGER}</td>
    <td>${item.NUM}</td>
    <td>${item.PHONE}</td>
    <td>
    ${item.HOTEL_ID }
    <%-- <lytag:lySelect name="" params="" tabName="BUS_BAS_HOTEL" combox="false" htmlAttr=" disabled='disabled'"
       dsCode="ADDR" dsValue="HOTEL_NAME" value="${item.HOTEL_ID }" headKey="" headValue="" /> --%>
    </td>
    <td>
    <c:choose>
    <c:when test="${item.PICK_UP_LOCATION eq '1'}">航班</c:when>
    <c:when test="${item.PICK_UP_LOCATION eq '2'}">火车</c:when>
    </c:choose>
    </td>
    <td><fmt:formatDate value="${item.PICK_UP_TIEM}" pattern="yy-MM-dd HH:mm"/></td>
    <td>${item.AMOUNT}</td>
   </tr>
 </c:forEach>
 </tbody>
 </table>
 </div>
</div>
<script type="text/javascript">
 //将车次基本信息 赋值到列表中
 $(function(){
    $("#DepartureTime").html('<fmt:formatDate value='${objEnt.DepartureTime }' pattern="yyyy-MM-dd HH:mm"/>');
 $("#StartSite").html('${objEnt.StartSite }');
 $("#EndSite").html('${objEnt.EndSite }');
 $("#MaxNo").html('${objEnt.MaxNo }');
 $("#ManNum").html('${objEnt.ManNum }');
  });
   //退出重排 remove
  function selected_remove_libe(selectedIds) {
  var ids = "";
  $("#car_play_lieb_tableid").find("input:checked").filter(
    "[name='" + selectedIds + "']").each(
  function(i) {
    var val = $(this).val();
    ids += i == 0 ? val : "," + val;
   });
   if(ids==''){
   alertMsg.warn("请选择要退出的订单!");
   return false;
   }
  
  var flag; //判断是否一个未选  
        $("input[name='ids_pany_value']:checkbox").each(function() { //遍历所有的name为selectFlag的 checkbox 
                 if ($(this).attr("checked")) { //判断是否选中   
                      flag = true; //只要有一个被选择 设置为 true 
                    }
                }); 
   if (flag) { 
            $("input[name='ids_pany_value']:checkbox").each(function() { //遍历所有的name为selectFlag的 checkbox
                  if ($(this).attr("checked")) { //判断是否选中   
                    $(this).parent("td").parent("tr").remove(); 
                            //alert($(this).val()); 
                            //array.push($(this).val()); //将选中的值 添加到 array中
                            //str+=$(this).val()+",";
                        }
                    });          
        //window.self.location = "deleteUser?info=" + array; 
        } else { 
            alert("请至少选择一个用户"); 
        } 
    }

0 0
原创粉丝点击