之前的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>
});

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>

解决方法

< TD>应始终在< tr>中.

我可能会让你的功能像这样:

$("#addMatch").click(function(){
    $(this).parents('tr:first').before('<tr><td>New Insert</td></tr>');
    return false;
});

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...