2013-10-08 14 views
1

當我刷新頁面時,它會在td中顯示值和圖像,但是當您單擊td時,它將在td中顯示編輯值之後執行內聯編輯功能在TD圖像消失了,我想要的形象穩定的TD被編輯後,任何人都可以看看我的代碼,引導me.thanks如何在成功後使用ajax顯示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> 
+0

如果您將問題的範圍縮小到相關代碼,或者更多地解釋您正在嘗試做什麼以及減少大量粘貼,它將對您有所幫助。 – Dave

+0

當我刷新頁面時,它顯示td中的值和圖像,但是當您單擊td時,它將在td中顯示編輯後的值後執行內聯編輯功能,td中的圖像在編輯td時消失 – Xavi

回答

0

在上點擊功能您td.edit你該單元格的HTML設置爲一個輸入框有效覆蓋圖像。修復它的唯一方法是在完成編輯後重置圖像或將圖像放入不同的單元格中。

相關問題