zoukankan      html  css  js  c++  java
  • yii2 框架中的即点即改入库

    视图层

    <td><span class='num'  id="<?php echo $value['goods_attr_id']?>"><?php echo $value['attr_value']?></span></td>

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    js代码

    <script src="../web/js/jquery-1.4.4.min.js"></script>
    <script type="text/javascript">
        $(function(){    
        $(document).on('click','.num',function(){    
            var id=$(this).attr('id');    
            var _this=$(this);    
            var new_val=$(this).html();    
            _this.parent().html("<input type='text' class='asdf' value="+new_val+" id="+id+">");    
            var inp=$('.asdf');    
            inp.focus();  
            inp.blur(function(){    
                var old_id=$(this).attr('id');  
                var old_val=$(this).val();    
               $.get("index.php?r=third/updategoods",{old_val:old_val,old_id:old_id},function(e){    
                   if(e==1)    
                    {    
                        inp.parent().html("<span class='num' id="+old_id+">"+old_val+"</span>");    
                    }    
                    else    
                    {      
                        inp.parent().html("<span class='num' id="+old_id+">"+new_val+"</span>");      
                    }      
                })    
            })    
        })   

    </script>

    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    控制器

    public function actionUpdategoods(){
       
            $request = Yii::$app->request;       
            $id = $request->get('old_id'); 
            $name = $request->get('old_val'); 
            $connection=Yii::$app->db; 
            $command = $connection->createCommand("
                                                UPDATE ecs_goods_attr SET attr_value='$name' WHERE attr_id='18' AND goods_attr_id='$id'
                                                "); 
            $re=$command->execute(); 
            if($re)    
            {    
                echo 1;    
            }
        }

  • 相关阅读:
    1-4-04:奇偶ASCII值判断
    1-4-03:奇偶数判断
    1-4-02:输出绝对值
    1-4-01:判断数正负
    1-3-20:计算2的幂
    1-3-19:A*B问题
    1-3-18:计算三角形面积
    Use PIVOT Table in SQL Server
    Pivoting DataTable Simplified
    Pivot Methods 行列转换
  • 原文地址:https://www.cnblogs.com/nycj/p/5940907.html
Copyright © 2011-2022 走看看