選中要洗掉的商品,點擊批量洗掉


- 先在控制器使用sql陳述句查出商品資訊goods
- 然后在html原始碼中使用goods變數,
<table> {foreach $goods as $item} <tr> <td><input name="ids" class="ids" type="checkbox" value="{$item.goods_id}"></td> <td>123</td> <td>2324</td> </tr> {/foreach} </table>
按鈕原始碼
<a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont"></i> 批量洗掉</a>
- js
function datadel(){ $ids = $("input[name='ids']:checked"); var checkID=[]; $("input[name='ids']:checked").each(function(i){ checkID[i] = $(this).val(); }); //判斷陣列是否為空,空的話禁止點擊 if(checkID.length == 0){ return; } // console.log(checkID); layer.confirm('確認要洗掉嗎?',function(index){ // $ids = $(".ids"); $.ajax({ type: 'POST', url:"{:url('productBatchDelAjax')}", data:{checkID:checkID}, dataType: 'json', success: function(data){ // alert(data); // $(obj).parents("tr").remove(); $ids.each(function(i){ $(this).parents("tr").remove(); // console.log($(this).parents("tr")); }); layer.msg('已洗掉!',{icon:1,time:1000}); }, error:function(data) { console.log(data.msg); }, }); }); }
- 控制器異步請求洗掉資料
public function productBatchDelAjax() { $data = https://www.cnblogs.com/mzzone/p/$_POST['checkID']; $DB = new Db; $res=$DB::table("goods")->delete($data); if($res){ echo"ok"; } }
- 注意:
- jquery如何把選中的id提交到后臺
$("input[name='ids']:checked").each(function(i){
checkID[i] = $(this).val();
});
2.如何在洗掉之后不重繪頁面能達到洗掉的效果,操作dom元素
$ids.each(function(i){ $(this).parents("tr").remove(); // console.log($(this).parents("tr")); });
3.tp5批量洗掉的語法,data是一個陣列,
$res=$DB::table("goods")->delete($data);
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/95116.html
標籤:PHP
上一篇:tp5.1 無限極分類前臺展示
