开发者

Jquery add tr to last but one row in a table

Sample Code

`<table>  
    <tr>    
<td> first column </td>    
</tr>  
<tr id ="addRow">   
<td><input type="button" id="add_button" name="add" value="Add" /></td>   
</tr>   
 </table>
`

Now when i click this Add button it should add tr before this row i.e

`<table>  
<tr>   
 <td> first column </td>    
</tr>  
<tr> 开发者_运维知识库   
 <td> some content </td>     
</tr> 
<tr id ="addRow">   
<td><input type="button" id="add_button" name="add" value="Add" />   
</td>    
</tr>   
 </table>
`

so the next time i click Add button it has to be

`<table>   
<tr>  
 <td> first column </td>   
 </tr>  
<tr>   
<td> some content </td>  
 </tr> 
<tr>   
<td> some content </td>    
</tr>
<tr id ="addRow">   
<td><input type="button" id="add_button" name="add" value="Add" /> </td>   
</tr>   
 </table>
`

How is this done?? Please help


$(function () {
$('#add_button').click(function () {
    $('<tr><td>Some content</td></tr>').insertBefore('#addRow');

});

}):


$("#add_button").click(function(){
    $('<tr><td/></tr>').insertBefore('#addRow');
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜