开发者

I want add a row a specific postion

开发者 https://www.devze.com 2023-03-17 01:19 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消