php - jquery Ajax 成功后突出显示数据

标签 php jquery mysql ajax

我正在通过 jquery Ajax 在我的网页中创建内联编辑

在我的代码中,我可以编辑表数据,但我想在编辑几秒钟的时间内突出显示更改的数据

我应用了许多代码,例如:

$("div").click(function () {
      $(this).effect("highlight", {}, 3000);
});

但这并没有给我正确的结果

这是我的 PHP 代码:

while($rows = mysql_fetch_array($result))
    {


        echo "<tr>";

        echo '<td>'.$rows["id"].'</td>
        <td class="edit uname '.$rows["id"].'">'.$rows["uname"].'</td>
        <td class="edit pass '.$rows["id"].'">'.$rows["pass"].'</td>

        </tr>';
    }

这是我的 jquery:

<script>
$(document).ready(function(){
    $('td.edit').click(function(){
        $('.ajax').html($('.ajax input').val());
        $('.ajax').removeClass('ajax');
        $(this).addClass('ajax');
        $(this).html('<input id="editbox" size="'+$(this).text().length+'" type="text" value="' + $(this).text() + '">');
        $('#editbox').focus();
    });

    $('td.edit').keydown(function(event){
        arr = $(this).attr('class').split(" ");
        if(event.which == 13) { 
            $.ajax({    
                type: "POST",
                url:"config.php",
                data: "value="+$('.ajax input').val()+"&rownum="+arr[2]+"&field="+arr[1],
                success: function(data){
                    $('.ajax').html($('.ajax input').val());
                    $('.ajax').removeClass('ajax');
                    $( "#toggle" ).toggle( "highlight" );
                }
            });
        }
    });

    $('#editbox').live('blur',function(){
        $('.ajax').html($('.ajax input').val());
        $('.ajax').removeClass('ajax');
    });

});

</script>

所以请 friend 们帮助我。

最佳答案

您可以在 td.edit 点击事件中添加突出显示效果

 $('td.edit').click(function(){

        $(this).parent().effect("highlight", {}, 3000); //create highlight effect on parent tr

        $('.ajax').html($('.ajax input').val());
        $('.ajax').removeClass('ajax');
        $(this).addClass('ajax');
        $(this).html('<input id="editbox" size="'+$(this).text().length+'" type="text" value="' + $(this).text() + '">');
        $('#editbox').focus();
    });

这是fiddle

关于php - jquery Ajax 成功后突出显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23335290/

相关文章:

javascript - 单击按钮保存客户端生成的图像

php - 在 PHP 中显示来自 MySQL 的结果旁边的图像?

python - 类型错误 : not enough arguments for format string in python

php - 获取最后插入行的主键 ID 以运行多个插入操作

php - 函数 : Database connection in function or pass it as argument? 的最佳情况是什么

php - PDO - 在没有警告的情况下不匹配的绑定(bind)变量数量

javascript - 显示 highchart 列范围图表 x 轴、y 轴和系列

javascript - 如何检索旧文本并从总数中减去 - JS

javascript - 如何映射输入字段的动态数组

php - 如何使用 PHP 的 SPL 聚合邻接列表的结果