Fly*_*Cat 6 html jquery insert
我试图插入一个块元素在另一个之前插入一些东西.我不确定我是否使用正确的方法,但这是我的代码.希望你们能帮忙.谢谢!
jQuery的
$("#addMatch").click(function(){
$("<td>New insert</td>").insertBefore("#addMatch").closest('tr');
return false; //this would insert the <td>New insert</td> before the
//<td><input type="button" id="addMatch" name="addMatch" value="Add
//Match" </td> but not <tr>
});
Run Code Online (Sandbox Code Playgroud)
HTML
<tr>
<td>some data</td>
</tr>
//can't tell how many tr would show before the last "addMatch" button. It's dynamic.
// I want the <td>New insert</td> show up here.
<tr>
<td><input type="button" id="addMatch" name="addMatch" value="Add Match" </td>
</tr>
Run Code Online (Sandbox Code Playgroud)
Ker*_*nes 13
<td>应该永远在一个<tr>.
我可能会让你的功能像这样:
$("#addMatch").click(function(){
$(this).parents('tr:first').before('<tr><td>New Insert</td></tr>');
return false;
});
Run Code Online (Sandbox Code Playgroud)