我们在开发项目的时候经常会在后台管理时用到批量展示功能来动态的修改数据库的值。下面以修改数据库的status状态值来实现批量展示功能。批量选中功能引用js来实现。
前端html代码:
<table class="mlt" style="border:1px solid red;"> <thead> <tr> <if condition="$type eq 'pg'"> <th colspan="9" style="text-align:left;padding-left:20px;background-color:#e5e4e4;color:#c10e23;">实物商品</th> <else/> <th colspan="8" style="text-align:left;padding-left:20px;background-color:#e5e4e4;color:#c10e23;">虚拟商品</th> </if> <th style="background-color:#e5e4e4;"> <a href="{:U('Mall/AddMall',array('type'=>$type))}" style="color:#c10e23;text-decoration:none;">+新增商品</a></th> </tr> <tr> <th style="background-color:#f7f7f7;width:8%;text-align:center;" class="lf"> <input name='chkAll' type='checkbox' id='chkAll' onClick="checkAll(this, 'id[]')" value='checkbox' /> 全选 </th> <th style="background-color:#f7f7f7;width:8%;" class="lf">商品编号</th> <th style="background-color:#f7f7f7;width:13%;" class="lf">名称</th> <th style="background-color:#f7f7f7;width:18%;" class="lf">标题</th> <if condition="$type eq 'pg'"> <th style="background-color:#f7f7f7;width:8%;" class="lf">品牌</th> </if> <th style="background-color:#f7f7f7;width:8%;" class="lf">组别</th> <th style="background-color:#f7f7f7;width:5%;" class="lf">排序</th> <th style="background-color:#f7f7f7;width:5%;" class="lf">状态</th> <th style="background-color:#f7f7f7;width:10%;">图标</th> <th style="background-color:#f7f7f7;text-align:center;" class="lf">操作</th> </tr> </thead> <tbody> <volist name="list" id="vo"> <tr> <td class="lf" style="text-align:center;"> <input name='id[]' type='checkbox' value='{$vo.id}' onClick="checkItem(this, 'chkAll')"> </td> <td class="lf">{$vo['code']}</td> <td class="lf">{$vo['name']}</td> <td class="lf">{$vo['title']}</td> <if condition="$type eq 'pg'"> <td class="lf">{$vo['brand']}</td> </if> <td class="lf">{$vo['ggroup']}</td> <td class="lf">{$vo['sortno']}</td> <td class="lf"><if condition="$vo['status'] eq 1">展示<else/>不展示</if></td> <td><img src="/UploadFiles/2021-04-02/{$vo['base_img']}">js代码使用ajax提交代码到后台GoodsShow()方法:
<script type="text/javascript"> var ids = []; //把得到的is转化为数组形式 $('#btn_show').click(function(){ btnCheck('展示'); data = { "ids":ids }; $.ajax({ type:"POST", url:"{:U('Mall/GoodsShow')}", data:data, //dataType:"json", success:function(msg){ if(msg == 00){ //如果msg=00则修改成功 alert("批量展示成功"); window.location.href='/index.php/Admin/Mall/MallList'; //修改完成后自动刷新 }else{ alert("批量展示失败,请重新编辑"); } }, error:function(){ alert("批量编辑失败,请重新编辑"); //错误提示 } }); });function btnCheck(info){ var obj = $("input[name='id[]']:checked").each(function(){ //得到选中的id的每一个值并且这个值为一个数组 ids.push($(this).val()); }); if (ids == false) { alert("请选定要"+info+"的商品"); return false; }else { return ids; } } </script>后台GoodsShow()方法:
public function GoodsShow(){ $goods=M('shop_goods_info'); //实例化要使用的数据表 $data = I(); //获取前台页面获取的id值(这个值为一个一位数组) //var_dump(I('ids'));die(); //打印 $id=implode(',',I('ids')); //把得到的这个数组用implode方法拆分 //var_dump(I('id'));die(); //打印查看 $order=$goods->where("id in ($id)")->setField('status','1'); //用得到的$id的值匹配数据库中的id值,并设置id下的status字段值为1. if($order>=1){ // 如果...else... $remark="00"; }else{ $remark="01"; } echo $remark; }以上所述是小编给大家介绍的使用JS批量选中功能实现更改数据库中的status状态值(批量展示),希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!
昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。
这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。
而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?
更新日志
2024年09月24日
2024年09月24日
- 张惠妹《ThePowerOfA-Mei》2018[SACD/ISO]
- 陈珊妮.2013-低调人生2CD【和气音乐】【WAV+CUE】
- 群星.2000-超级BAND.BAND.BAND【滚石】【WAV+CUE】
- 许志安.2002-On.Show演唱会2CD(2024环球红馆40复刻系列)【环球】【WAV+CUE】
- 蔡琴-哈利路亚2016[SACD/ISO]
- 陈随意2011-今生只为你[豪记][WAV+CUE]
- 陈随意2008-爱的总铺师[美华][WAV+CUE]
- 裘德《一棵树所创造的》[320K/MP3][56.21MB]
- 裘德《一棵树所创造的》[24bit 48kHz][FLAC/分轨][355.1MB]
- 卓依娜姆《美人谋 网剧影视原声带》[320K/MP3][48.29MB]
- 张星特.2024-流绪呢喃【中视鸣达】【FLAC分轨】
- 邓紫棋.2010-MYSECRET【蜂鸟音乐】【WAV+CUE】
- 江惠仪.2011-感謝您【禾广娱乐】【FLAC分轨】
- 韩红2005-精选[首版][WAV+CUE]
- 张敬轩.2004-A.M/P.M【几何文化】【WAV+CUE】