javascript - 成功后如何使用ajax在td中显示值和图像

标签 javascript php jquery html ajax

当我刷新页面时,它会在 td 中显示值和图像,但是当您单击 td 时,它将在 td 中显示编辑后的值后执行内联编辑功能,td 中的图像消失,我希望图像在之后稳定td 已编辑,任何人都可以看一下我的代码并指导我。谢谢

下面是我的代码

Ajax

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

            $('.ajax').html($('.ajax input').val());
            $('.ajax').removeClass('ajax');

            $(this).addClass('ajax');
            $(this).html('<input id="editbox"  size="10" 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: "supplierprice/config.php",
                    data: "value=" + $('.ajax input').val() + "&rowid=" + arr[2] + "&field=" + arr[1],
                    success: function (data) {

                        $('.ajax').html($('.ajax input').val());
                        $('.ajax').removeClass('ajax');


                    }
                });
            }
        }


    );


    $('#editbox').live('blur', function () {

        $('.ajax').html($('.ajax input').val());
        $('.ajax').removeClass('ajax');


    });

});

HTML:

<table id="sorting" class="tablesorter" style="width: 100px;" >        
<tbody >
<?php

$sql = mysql_query("SELECT * FROM supplierprice ");


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

if($alt == 1)
        {
           echo '<tr class="alt">';
           $alt = 0;
        }
        else
        {
           echo '<tr>';
           $alt = 1;
        }

echo '  <td class="edit region '.$rows["supp_price_id"].'">'.$rows["region"].'</td>
        <td class="edit country '.$rows["supp_price_id"].'">'.$rows["country"].'</td>
        <td class="edit networkname '.$rows["supp_price_id"].'">'.$rows["networkname"].'</td>
        <td class="edit mcc '.$rows["supp_price_id"].'">'.$rows["mcc"].'</td>    
        <td class="edit mnc '.$rows["supp_price_id"].'">'.$rows["mnc"].'</td>
        <td class="edit mnp '.$rows["supp_price_id"].'">'.$rows["mnp"].'</td>';


$ColumnNames = mysql_query("SELECT column_name FROM information_schema.COLUMNS WHERE table_name = 'supplierprice' AND column_name NOT
IN ('supp_price_id','region', 'country', 'networkname', 'mcc', 'mnc', 'mnp'
)") or die("mysql error"); 
$columnArray=array();
$i=0;
while($rows1=mysql_fetch_array($ColumnNames))
{

$columnArray[]=$rows1[0];

echo '<td width="0px;" class="edit '.$columnArray[$i].' '.$rows["supp_price_id"].'">'.$rows[$columnArray[$i]].'<div style="margin:0px;"><a class="big-link" data-reveal-id="myModal">
            <span>  <img id="logo"  src="/image/Picture8.png" style="margin:0px;cursor:pointer;"></span>
        </a> <a class="big-link" data-reveal-id="doubleModal">
            <span>  <img id="logo"  src="/image/Picture7.png" style="margin:0px;cursor:pointer;"></span>
        </a> <div> </td>';          


$i++;
}    
echo '</tr>';
    }
    ?>
       </tbody>
       </table>

最佳答案

在 td.edit on click 函数中,您将该单元格的 HTML 设置为输入框,从而有效地覆盖图像。解决此问题的唯一方法是在完成编辑后重置图像或将图像放入不同的单元格中。

关于javascript - 成功后如何使用ajax在td中显示值和图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19249484/

相关文章:

javascript - DIV 元素的 Border-Radius 在 IE8 中不起作用

javascript - 如何使用附加数据更新现有对象

javascript - unitPngFix 防止更改隐藏的 "display"的 "div"

javascript - 在确认删除之前进行 AJAX 检查

javascript - 是否保证在 webpack 或 rollup 模块打包过程中保留单例?

带连接字符串的 PHP 变量变量名

php - 接口(interface)依赖注入(inject)

PHP - htmlspecialchars 和 UTF-8

javascript - 选择的 jQuery 插件不起作用。

javascript - jQuery:将输出的文本包装在跨度中?