后台无刷新修改字段js

视图:

<tr data='{cid:"<?php echo $one['id']; ?>"}'>
    <td width="40"><div class="dis"><img src="<?php echo Yii::app()->request->baseUrl; ?>/images/ico_edit.png" class="bt_modify" width="15" height="15"></div></td>
          <td>
              <span class="t"><?php echo $one['title']; ?></span>
              <input type="text" class="input_s it" style="200px; display:none" value="<?php echo $one['title']; ?>"/>
          </td>
                               
 </tr>

js:

  $(".tbody").mouseover(function(){
            $(this).find(".dis").show();                                       //鼠标移入行内图标显示
        }).mouseout(function(){$(this).find(".dis").hide();});                 //移出消失
    
        $(".bt_modify").click(function(){
           $(this).parent().parent().parent().find(".t").hide();               //点击图片原字段隐藏
            $(this).parent().parent().parent().find(".it").show().focus();     //显示并且选中input框
        });
        
        $(".it").blur(function(){
            $(this).hide();
            $(this).parent().find(".t").show();
            var data = eval('('+$(this).parent().parent().attr('data')+')');
            var cid = data.cid;
            var obj = $(this);
            var objSpan = $(this).parent().find(".t");
            var title = $.trim($(obj).val());
            var origin = $(objSpan).html();
            if (title == "") {
                $.messager.show({
                    title:'提示',
                    msg:'标题不能为空',
                    showType:'fade',
                    style:{
                        right:'',
                        bottom:''
                    }
                });
                $(obj).val(origin);
                return false;
            }
            if (title == origin) {
                $(this).hide();
                $(this).parent().find(".t").show();
            } else {
                $.post(
                '<?php echo Yii::app()->createUrl("content/edit") ?>',
                {'cid':cid,'title':title},
                function(data){
                    if(data.code < 1){
                        $.messager.alert("提示", data.message);
                    } else {
                        $(objSpan).html(title);
                        $(obj).hide();
                        $(objSpan).show();
                    }
                },
                'json'
            );
            }
        });

  

原文地址:https://www.cnblogs.com/fengzhiqiangcaisangzi/p/3380965.html