°渐行渐远っ
程序员的修仙之路
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>实现即点即修改</title>
</head>
<body>
	<center>
    <h1></h1>
    <table border="1">
        <tr>
            <td>id</td>
            <td>TITLE</td>
        </tr>
        <tr>
            <td>{$data.d_id}</td>
            <td>
            <span id='g_span'>{$data.d_title}</span>
            <input type="hidden" value="{$data.d_title}" id="hid" class="{$data['d_id']}">
            </td>
        </tr>
    </table>
</center>
</body>
<!-- 引入jquery文件 -->
<script src="__PUBLIC__/jquery.1.12.min.js"></script>
<script>
/*即点即改*/
    $(document).on('click','#g_span',function(){

        $(this).hide();

        $(this).next().prop('type','text');

    })
    /*给输入框失去焦点事件,获取内容,传到后台更新*/
    $(document).on('blur','#hid',function(){
       var g_title = $(this).val();
        var g_id = $(this).prop('class');
        var obj = $(this);
        $.ajax({
            url:"{:U('Index/save_title')}",
            type:'get',
            data:"g_id="+g_id+"&g_title="+g_title,
            dataType:'json',
public function save_title(){
    //接修改的内容
        $d_title = I('get.g_title');
        //接修改的id
        $d_id = I('get.g_id');
        $goods_obj = M('z_title'); 
        $data['d_title'] = $d_title;
        $res = $goods_obj->where("d_id=".$d_id)->save($data);     
        if($res){
            echo 0;
        }else{
            echo -1;
        }
    

 

            success:function(msg){   
                if(msg == -1){
                    alert('修改失败');
                }
                obj.prev().show();
                obj.prop('type','hidden');
                obj.prev().text(g_title);
            }
        })
    })
</script>
</html>
 1 public function save_title(){
 2     //接修改的内容
 3         $d_title = I('get.g_title');
 4         //接修改的id
 5         $d_id = I('get.g_id');
 6         $goods_obj = M('z_title'); 
 7         $data['d_title'] = $d_title;
 8         $res = $goods_obj->where("d_id=".$d_id)->save($data);     
 9         if($res){
10             echo 0;
11         }else{
12             echo -1;
13         }
14     }

代码当中还存在着不足,发现问题可以提出来,让我改进。大家共同进步!!!

本文为原创!!转载请注明出处谢谢!!

 

posted on 2017-04-27 14:26  &#176;渐行渐远っ  阅读(197)  评论(0编辑  收藏  举报