jquery批量删除

即点即改关键在于取到父节点的id值 来根据id去修改

示例:

这是一个基本的循环的表格

<input type="button" value="批量删除" class="ui_input_btn01" id="dels" /> 
<tr>
   <th width="30"><input type="checkbox" id="all" />
   </th>
   <th>位置</th>
   <th>房源</th>
   <th>房源面积</th>
   <th>户型</th>
   <th>带看次数</th>
   <th>时间</th>
   <th>价格</th>
   <th>状态</th>
   <th>操作</th>
</tr>
<tbody id="search"><?php foreach($model as $key=>$val){?> <tr id="<?php echo $val['h_id']?>"> <td><input type="checkbox" class="che" name="check" value="<?=$val['h_id']?>"/></td> <td><?= $val['address']; ?></td> <td><?= $val['name']; ?></td> <td><?= $val['area']; ?></td> <td><?= $val['a_name']; ?></td> <td><?= $val['desc'];?></td> <td><?= $val['time']; ?></td> <td><?= $val['price']; ?></td> <td> <?php if($val["state"]==0) { echo "<span >未出租</span>"; }else { echo "<span >已出租</span>"; } ?> </td> <td> <a href="javascript:void(0);" id="update" title="<?=$val['h_id']?>">编辑</a> <a href="javascript:void(0);" id="del" title="<?=$val['h_id']?>">删除</a> </td> </tr>
修改
$(document).on("click","span",function () {
      var _this =  $(this);
      var text = _this.html();
      var id=_this.parents("tr").attr('id');
      var state='';
      if(text=='未出租')
      {
         _this.text("已出租");
         state=1;
      }
      else
      {
         _this.text("未出租");
         state=0;
      }
      $.ajax({
         type: "get",
         data: {state:state,id:id},
         url:"?r=user/upstate",
         success: function(msg)
         {
这部分是要传的后台根据状态 id 来进行修改 实现正真的改。
         }
      })
   })
全反选

根据属性去选择,

$(document).on("click","#all",function()
{     
   if(this.checked)
   {
      $(".che").prop("checked", true);
   }else
   {
      $(".che").prop("checked", false);
   }
})
反选
$("#fan").click(function () {
    $(".a:checkbox").each(function () {
        $(this).prop("checked", !$(this).prop("checked"));
    });
})
批量删除
$("#dels").click(function(){
//    alert("ds");
            var checkedNum = $("input[name='check']:checked").length;
            if(checkedNum == 0) {
                alert("请选择至少一项!");
                return;
            }
// // 批量选择
            if(confirm("确定要删除所选项目?")) {
                var che = $("input[name='check']:checked");
//              alert(che)
                var hh = new Array();
                for(var a=0;a<che.length;a++){
                    hh[a] = che[a].value;
                }
                $.ajax({
                    type: "POST",
                    url: "?r=user/dels",
                    data: {'delitems':hh},
                    success: function(result) {
                        alert("删除成功");
                    }
                });
            }
        });
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值