我有以下 HTML
<tbody class="t_bdy">
<tr class="Quotation_List_td">
<td class="item"><a class="button2 crm_insert" href="#">Insert</a><a class="button2 crm_delta" href="#">Delete</a></td>
<td class="Quotation_List_ItemTD description"> </td>
<td class="quantitiy"> </td>
<td class="unit_price"> </td>
<td class="discount"> </td>
<td class="total"> </td>
</tr>
<tr class="Quotation_List_td">
<td class="item"><a class="button2 crm_insert" href="#">Insert</a><a class="button2 crm_delta" href="#">Delete</a></td>
<td class="Quotation_List_ItemTD description"> </td>
<td class="quantitiy"> </td>
<td class="unit_price"> </td>
<td class="discount"> </td>
<td class="total"> </td>
</tr>
</tbody>
我需要插入新的 <tr>
当我点击带有 .crm_insert
的按钮时类。
当 .crm_insert
被点击,需要在当前位置插入一个新行。全部
其他行将向下移动。例如,如果单击第 3 行的插入,则
第 3 行将插入新行,当前第 3 行等将向下移动成为
第 4 行等
我怎样才能做到这一点?
所有答案都很好,但我只能接受一个:谢谢大家
最佳答案
我会尝试使用 closest() 和 before()
$('a.crm_insert')
.click(function()
{$(this).closest('tr.Quotation_List_td').before(htmlcodeofyounewTRhere);}
)
希望对你有帮助
关于javascript - jQuery 替换和添加新元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9565406/