</center> <table id="sample-table-1" class="table table-striped table-bordered table-hover"> <thead> <tr> <th class="center"> <label> <input type="checkbox" class="ace" /> <span class="lbl"></span> </label> </th> <th>商品编号</th> <th>商品名称</th> <th>商品图片</th> <th>所属分类</th> <th>水果重量</th> <th>水果库存</th> <th>已销售量</th> <th>产地</th> <th>销售价</th> <th>会员价</th> <th>是否上架</th> <th>是否参与活动</th> <th>操作</th> </tr> </thead> <tbody class="body"> {foreach name='data' item='v'} <tr> <td class="center"> <label> <input type="checkbox" class ='box' name="box" alt="{$v.f_id}"/> <span class="lbl"></span> </label> </td> <td>{$v.f_id}</td> <td>{$v.f_name}</td> <td><img src="<?php echo $v['f_img'];?>" alt="" width="50"></td> <td>{$v.t_name}</td> <td>{$v.f_weight}</td> <td>{$v.f_surplus}</td> <td>{$v.f_sale}</td> <td>{$v.f_place}</td> <td>{$v.m_price}</td> <td>{$v.v_price}</td> <td> {if condition="$v.is_show == 1"} 上架 {else /} 下架 {/if} </td> <td> {if condition="$v.is_hot== 1"} 参与活动 {else /} 不参与活动 {/if} </td> <td> <a href="{:url('index/Goods/modify')}?fid={$v.f_id}">编辑</a> <button class="del" alt="{$v.f_id}">删除</button> </td> </tr> {/foreach} </tbody> </table> <center> <table > <script> //单删 $('.del').click(function(){ var fid=$(this).attr('alt'); var _this=$(this); // alert(fid); $.ajax({ type: "GET", url: "index.php/index/goods/del", data: "fid="+fid, success: function(msg){ if(msg==1){ _this.parent().parent().remove(); alert('删除成功'); }else { alert('删除失败'); } } }); }) </script>
//单删
public function del(){
$fid=$_GET['fid'];//获取商品id
$res=Db::table('sg_fruits')->where("f_id= $fid")->delete();
if($res){
echo 1;
}else{
echo 2;
}
}