I want add a row a specific postion. and i have all row id for example i have table In table rows have one button when i click on buttton row become instered below button click row
ASP.NET MVC COde
<%For开发者_运维技巧 i = 0 To 9%>
<tr>
<td><input type="button" value="<%:i.ToString %>" onclick ="alert('<%:i.ToString %>')" /></td>
<td>hhhhhhhhhhhhhhhhhhhh</td>
<td>wwwwwwwwwwwwwwwwwwwwwwwww</td>
</tr>
<%next %>
var x = '<tr><td>New Row</td></tr>'
$('#button').live('click', function() {
var parentTr = $(this).closest('tr');
$(x).insertBefore(parentTr);
})
Check working example at http://jsfiddle.net/9vXtV/1/
You could do this:
$("#your_table").append( $("#your_table tr:last").clone() );
This clones the last row and adds it to the table
Something more or less like this:
var newRow = $('#table tr:last').clone();
$('.button').click(function() {
$(this).closest('tr').after(newRow.clone());
});
In this example I assume that the last row is an empty row on page load.
精彩评论