如何在jQuery中的特定ID之后追加 [英] How to append after a specific id in jquery

查看:103
本文介绍了如何在jQuery中的特定ID之后追加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,我有一张桌子,我想动态地在其中添加带有列的行,但不要在结尾处添加,我希望将其添加到特定行的ID之后.该怎么做?

Guys I have a table and I want to dynamically append a row with column inside it but not at the end, I want it to be appended after a specific id of a row. How to do that?

$('#add-another-file').live('click', function() {
   $('#to-upload-table').append('<tr><td><input type="file" name="file-upload" id="file-upload" ></td></tr>');     
});

这是我的代码,但是它将在最后一行之后追加新元素.

That is my code, but it will append the new element after the last row.

这是我要在其中添加新行的html:

Here's my html where i want the new row to be appended:

<table width="100%" style="border-collapse: separate;" id="to-upload-table">

        <tr>
            <td>
                <input type="file" id="file_upload" name="file_upload">
            </td>
        </tr>

        <tr>
            <td>
                <input type="file" id="file_upload" name="file_upload">
            </td>
        </tr>
        <tr>
            <td>
                <input type="file" id="file_upload" name="file_upload">
            </td>
        </tr>
        <tr>
            <td>
                <input type="file" id="file_upload" name="file_upload">
            </td>
        </tr>

        <tr align="right">
            <td>
                <input type="button" id="add-another-file" name="add-another-file" value="Add another file" >
            </td>
        </tr>
        <tr align="right">
            <td>
                <a href="#" id="single-file">Single-file </a>
            </td>
        </tr>
        <tr>
            <td align="right">
                <input type="button" id="upload_file" value="Upload">
            </td>
        </tr>
    </table>

如您所见,表的最后一部分上有三个按钮,我希望将新行附加在这三个按钮之前.输入这些文件之后

As you can see, there are three buttons on the last part of the table, I want the new row to be appended just before those three buttons. After those file input types

推荐答案

使用 jQuery After :

$('targeted row to append after').after('<tr><td><input type="file" name="file-upload" id="file-upload" ></td></tr>');

您可以在此处查看DOM插入方法的列表: http://api.jquery.com/类别/操作/

You can check the list of DOM insertion methods here : http://api.jquery.com/category/manipulation/

这篇关于如何在jQuery中的特定ID之后追加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆