示例代码
`<table>
<tr>
<td> first column </td>
</tr>
<tr id ="addRow">
<td><input type="button" id="add_button" name="add" value="Add" /></td>
</tr>
</table>
`
现在,当我点击此添加按钮时,它应该在此行之前添加tr,即
`<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>
`
所以下次我点击添加按钮时,它必须是
`<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>
`
这是怎么做到的?请帮忙
答案 0 :(得分:3)
$(function () {
$('#add_button').click(function () {
$('<tr><td>Some content</td></tr>').insertBefore('#addRow');
});
}):
答案 1 :(得分:1)
$("#add_button").click(function(){
$('<tr><td/></tr>').insertBefore('#addRow');
});