当我刷新页面时,它在 td 中显示值和图像,但是当您单击 td 时,它将在 td 中显示编辑后的值后执行内联编辑功能,td 中的图像消失,我希望图像在 td 编辑后稳定,任何人都可以看看我的代码并指导我。谢谢
下面是我的代码
阿贾克斯
$(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>