我们在开发项目的时候经常会在后台管理时用到批量展示功能来动态的修改数据库的值。下面以修改数据库的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状态值(批量展示),希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
标签:
js,数据库status
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
暂无“使用JS批量选中功能实现更改数据库中的status状态值(批量展示)”评论...
P70系列延期,华为新旗舰将在下月发布
3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。
而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?
根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。
更新动态
2024年05月09日
2024年05月09日
- 黄征-爱情诺曼底-2003-APE整轨
- 妥协只是暂时的!《对马岛之魂》PC版的多人模式仍需绑定PSN
- 开启抢先体验后 《盗贼之海》成PS美国第二畅销游戏
- 《恶意不息》老板再用中文询问中国玩家:对汉化是否满意
- 2个女生.2000-坚固友情精选辑【EMI百代】【WAV+CUE】
- 潘越云李丽芬吴楚楚.1981-三人展(滚石民歌巨星系列)【滚石】【WAV+CUE】.
- 元若蓝.2006-爱无限大【滚石】【WAV+CUE】
- 刘德华《经典传说·粤语精选集》[WAV/分轨][610MB]
- 庄心妍《2020年新专辑歌曲 念》[WAV/分轨][400MB]
- 群星《音色精美绝伦 粤语经典 2CD》[WAV+CUE][1.4GB]
- 欢乐钓鱼大师不充钱怎么玩 欢乐钓鱼大师不充钱搞鱼竿玩法介绍
- 欢乐钓鱼大师隐藏奖励有什么 欢乐钓鱼大师隐藏奖励介绍
- 欢乐钓鱼大师橙色鱼竿哪个好 欢乐钓鱼大师橙色鱼竿选择攻略
- 《最后的克劳迪亚》基础攻略 简述+配置+下载
- 《下一站江湖2》5月3日更新内容介绍