首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在jquery中的特定id之后追加

如何在jquery中的特定id之后追加
EN

Stack Overflow用户
提问于 2013-09-27 01:30:42
回答 2查看 1.5K关注 0票数 0

伙计们,我有一个表,我想动态地添加一个列在其中的行,而不是在它的末尾,我希望它被追加到一个特定的行id之后。怎么做?

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

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

下面是我的html,我希望在这里追加新行:

代码语言:javascript
复制
<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>

如您所见,表的最后部分有三个按钮,我希望在这三个按钮之前追加新行。在这些文件输入类型之后

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-09-27 01:31:20

使用jQuery后

代码语言:javascript
复制
$('targeted row to append after').after('<tr><td><input type="file" name="file-upload" id="file-upload" ></td></tr>');

您可以在这里检查DOM插入方法的列表:http://api.jquery.com/category/manipulation/

票数 2
EN

Stack Overflow用户

发布于 2013-09-27 01:33:09

如果没有.eq().after(),您可以使用id

代码语言:javascript
复制
$('#add-another-file').live('click', function() {
  $('#to-upload-table tr').eq(Number Here).after('<tr><td><input type="file" name="file-upload" id="file-upload" ></td></tr>');     
});
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19041341

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档