2012-07-29 25 views
1
<a class="checkModelButton" href="addrow.php">ADD ROW</a> 
<table> 
    <thead> 
     <th>Name</th> 
    </thead> 
    <tboby id="model_row"> 
     <tr>Nokia N70</tr> 
    </tbody> 
</table> 

和jQuery:在php和jquery中添加行時出錯?

jQuery('.checkModelButton').click(function(){ 
    var url = jQuery(this).attr('href'); 
    jQuery.ajax({ 
     type:'get', 
     cache: false, 
     url: url, 
     success: function(html){ 
     jQuery('#model_row').html(html); 
     } 
    }); 
}); 

文件addrow.php

<tr>Nokia N71</tr> 

當我點擊一個標籤結果:

<table> 
     <thead> 
      <th>Name</th> 
     </thead> 
     <tboby id="model_row"> 
      <tr>Nokia N71</tr> 
     </tbody> 
    </table> 

如何解決它導致是:

<table> 
     <thead> 
      <th>Name</th> 
     </thead> 
     <tboby id="model_row"> 
      <tr>Nokia N70</tr> 
      <tr>Nokia N71</tr> 
     </tbody> 
    </table> 

回答

3

使用.append() OR .appendTo()而不是.html()

success: function(html){ 
     jQuery('#model_row').append(html); 
     } 

OR

success: function(html){ 
      jQuery(html).appendTo('#model_row'); 
      } 
0

使用.html()將覆蓋內容。

您需要添加它。

$('#model_row').append(html); 
+0

@AnkitGautam:我沒有看到他的HTML結構。我認爲這是一個行,這就是爲什麼我使用'insertAfter()' – 2012-07-29 06:42:23