• sku 加减号的增删


    ---恢复内容开始---


    //php页面
    public function test(){
       $id="1";
       $data=Db::table('week3_goods')
           ->join("week3_hp","week3_goods.g_id=week3_hp.goods_id")
           ->join("week3_goods_attr","week3_hp.g_a_id=week3_goods_attr.g_a_id")
           ->where("week3_goods.g_id",$id)
           ->select();
        //print_r($data);die;
      foreach($data as $k =>$v){
          if($v['a_id']){
              $ids=explode(',',$v['a_id']);
              foreach($ids as $kk =>$vv){
                  $res=Db::table('week3_attr')->where("a_id",$vv)->find();
                  $ids[$kk]=$res['a_val'];
                  $data[$k]['attr']=$ids;
              }
          }
      }
        $color=Db::table('week3_attr')->where("a_name",'颜色')->select();
        $buttor=Db::table('week3_attr')->where("a_name","内存")->select();
        return view("index",['color'=>$color,'buttor'=>$buttor,'arr'=>$data]);
    }
    
    //添加数据
    public function add(){
        $data=Request::instance()->param();
        foreach($data['color'] as $k =>$v){
            $arr['goods_id']=$data['goods_id'];
            $arr['attr']=$data['color'][$k].",".$data['buttor'][$k];
            $arr['hp_num']=$data['hp_num'][$k];
            $arr['stock']=$data['stock'][$k];
            $res[]=$arr;
        }
        print_r($res);
    }

    //hrml页面 循环输出数据

    <center>
        <tr>
        <th>
            商品名称:{$arr[0]['g_name']}
            货物:{$arr[0]['hp_num']}
        </th>
    </tr>
        <table>
            <form action="{:url('login/add')}">
                <input type="hidden" value="{$arr[0]['goods_id']}" name="goods_id"/>
                <tr>
                    <td>颜色</td>
                    <td>内存</td>
                    <td>货号</td>
                    <td>库存</td>
                    <td>操作</td>
                </tr>
                {volist name="arr" id="vv"}
                <tr>
                    <td>
                        <select name="color[]" id="color">
                            <?php foreach($color as $k =>$v){?>
                            <option value="<?php echo $v['a_id']?>"
                                <?php if($v['a_val']==$vv['attr'][0]){
                             echo "selected";
                             } ?>><?php echo $v['a_val'];?>
                           </option>
                            <?php }?>
                        </select>
                    </td>
                    <td>
                        <select name="buttor[]" id="buttor">
                            <?php foreach($buttor as $k =>$v){?>
                            <option value="<?php echo $v['a_id']?>"
                            <?php if($v['a_val']==$vv['attr'][0]){
                             echo "selected";
                             } ?>><?php echo $v['a_val'];?>
                            </option>
                            <?php }?>
                        </select>
                    </td>
                    <td><input type="text" value="{$vv['hp_num']}" name="hp_num[]"/></td>
                    <td><input type="text" value="{$vv['stock']}" name="stock[]"/></td>
                    <td><input type="button" value="+" class="jia"/></td>
                </tr>
                {/volist}
                <tr>
                    <td><input type="submit" value="添加"/></td>
                </tr>
            </form>
        </table>
    </center>
    
    
    //jquery   界面
    
    //加减号的改变
    $(document).on('click','.jia',function(){
        var obj=$(this).parents("tr").clone();
        obj.find(".jia").attr('value','-');
        obj.find(".jia").attr('class','jian');
        $(this).parents("tr").after(obj);
    });
    
    $(document).on('click','.jian',function(){
        $(this).parents("tr").remove();
    });

    ---恢复内容结束---


    //php页面
    public function test(){
       $id="1";
       $data=Db::table('week3_goods')
           ->join("week3_hp","week3_goods.g_id=week3_hp.goods_id")
           ->join("week3_goods_attr","week3_hp.g_a_id=week3_goods_attr.g_a_id")
           ->where("week3_goods.g_id",$id)
           ->select();
        //print_r($data);die;
      foreach($data as $k =>$v){
          if($v['a_id']){
              $ids=explode(',',$v['a_id']);
              foreach($ids as $kk =>$vv){
                  $res=Db::table('week3_attr')->where("a_id",$vv)->find();
                  $ids[$kk]=$res['a_val'];
                  $data[$k]['attr']=$ids;
              }
          }
      }
        $color=Db::table('week3_attr')->where("a_name",'颜色')->select();
        $buttor=Db::table('week3_attr')->where("a_name","内存")->select();
        return view("index",['color'=>$color,'buttor'=>$buttor,'arr'=>$data]);
    }
    
    //添加数据
    public function add(){
        $data=Request::instance()->param();
        foreach($data['color'] as $k =>$v){
            $arr['goods_id']=$data['goods_id'];
            $arr['attr']=$data['color'][$k].",".$data['buttor'][$k];
            $arr['hp_num']=$data['hp_num'][$k];
            $arr['stock']=$data['stock'][$k];
            $res[]=$arr;
        }
        print_r($res);
    }

    //hrml页面 循环输出数据

    <center>
        <tr>
        <th>
            商品名称:{$arr[0]['g_name']}
            货物:{$arr[0]['hp_num']}
        </th>
    </tr>
        <table>
            <form action="{:url('login/add')}">
                <input type="hidden" value="{$arr[0]['goods_id']}" name="goods_id"/>
                <tr>
                    <td>颜色</td>
                    <td>内存</td>
                    <td>货号</td>
                    <td>库存</td>
                    <td>操作</td>
                </tr>
                {volist name="arr" id="vv"}
                <tr>
                    <td>
                        <select name="color[]" id="color">
                            <?php foreach($color as $k =>$v){?>
                            <option value="<?php echo $v['a_id']?>"
                                <?php if($v['a_val']==$vv['attr'][0]){
                             echo "selected";
                             } ?>><?php echo $v['a_val'];?>
                           </option>
                            <?php }?>
                        </select>
                    </td>
                    <td>
                        <select name="buttor[]" id="buttor">
                            <?php foreach($buttor as $k =>$v){?>
                            <option value="<?php echo $v['a_id']?>"
                            <?php if($v['a_val']==$vv['attr'][0]){
                             echo "selected";
                             } ?>><?php echo $v['a_val'];?>
                            </option>
                            <?php }?>
                        </select>
                    </td>
                    <td><input type="text" value="{$vv['hp_num']}" name="hp_num[]"/></td>
                    <td><input type="text" value="{$vv['stock']}" name="stock[]"/></td>
                    <td><input type="button" value="+" class="jia"/></td>
                </tr>
                {/volist}
                <tr>
                    <td><input type="submit" value="添加"/></td>
                </tr>
            </form>
        </table>
    </center>


    //jquery 界面

    //加减号的改变
    $(document).on('click','.jia',function(){
        var obj=$(this).parents("tr").clone();
        obj.find(".jia").attr('value','-');
        obj.find(".jia").attr('class','jian');
        $(this).parents("tr").after(obj);
    });
    
    $(document).on('click','.jian',function(){
        $(this).parents("tr").remove();
    });
  • 相关阅读:
    编码实现Spring 利用@Resource注解实现bean的注入,xml实现基本数据类型的注入
    Spring依赖注入
    Spring的DI(Ioc)
    Spring的DI(Ioc)
    Spring的DI(Ioc)
    Spring管理bean的生命周期
    Spring管理Bean的三种创建方式
    简单模拟Spring管理Bean对象
    编写spring配置文件时,不能出现帮助信息
    Spring简介
  • 原文地址:https://www.cnblogs.com/chaihtml/p/9839482.html
Copyright © 2020-2023  润新知