2010-07-30 56 views
0

我正在寻找使用jQuery以下要求动态添加行到我的HTML表。动态添加行jQuery - (复制现有的HTML)

该表有9列,其中1列有一个用于添加新行的按钮。 添加的新行应该添加在当前行之后,并且前7列为空,第8列应该是先前行8列的精确副本,并且第9列应该具有用于​​添加另一行/删除行的选项(类似于+/-按钮)。

我的HTML代码如下:

<table id='contactInfo'> 
    <thead>...</thead> 
    <tbody> 
     <tr> 
      <td>...data for the first 7 columns..</td> 
      <td> 
       <input type="text" id="newContactComment<%=rCount %>" name="newContactComment" size="45"> 
       <br> 
       <input type="checkbox" id="commentText<%=rCount %>" name="commentText" value="<%=c.getComment_text() %>" class="consComment">&nbsp; 
       <%=c.getComment_text() %><br> 

而jQuery代码如下:

$("#contactInfo").each(function(){ 
    $("button.addCommentRow", this).live('click', function() { 
     var html = '<tr><td>..blanks for first 7 columns </td> <td>...what goes in here..??..</td> </tr>'; 
     var row = $(this).closest('tr'); // get the parent row of the clicked button 
     $(html).insertAfter(row); // insert content 
       ...code to delete the newly added row.. 

我包括我是弄不清“发生的事情的一部分这里.. ?? ..'
任何建议/想法将不胜感激。

谢谢,
Pritish。

+0

您需要重新复制你的HTML,并与以前四个空格格式化的第八列的内容。看看我纠正你的jQuery部分的方式。 (提示:有一个代码按钮可以帮你做到这一点。) – MvanGeest 2010-07-30 16:53:42

回答

0

获得点击排

​​