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;    
            }
        }

  • 相关阅读:
    [GEiv]第七章:着色器 高效GPU渲染方案
    Cocos2d-x 脚本语言Lua介绍
    TestNg依靠先进的采用强制的依赖,并依赖序列的------TestNg依赖于特定的解释(两)
    uboot通过使用U磁盘引导内核RT5350成功
    linux下一个rsync工具和配置
    STM32 模拟I2C (STM32F051)
    Something write in FSE 2014
    ESB (Enterprise Service Bus) 入门
    Spring框架:Spring安全
    “TNS-03505:无法解析名称”问题解决一例
  • 原文地址:https://www.cnblogs.com/nycj/p/5940907.html
Copyright © 2011-2022 走看看