jquery - 通过 jquery 添加的 css id 不起作用

标签 jquery html css

我通过 jquery 动态添加 html 中的表格。我可以补充。但我无法删除添加的表。从 jquery 附加的 CSS“删除”id 不起作用。 “删除”ID 添加到脚本最后的部分标记中

Jquery

    $().ready(function(){
        $('#AddMoreId').on('click', function(){
                $('article:last').append('<article class="col100 left bggreen"><table><tr><th>ID</th><td><input type="number" id="id"></td></tr><tr><th>Menu in NPL</th><td><input type="text" id="menunep"></input></td></tr><tr><th>Menu in ENG</th><td><input type="text" id="menueng"></input></td></tr></table><section class="col100 left cursorpointer" id="remove">Remove</section></article><br/>');
        });

        $('#remove').on('click', function(){ 
            $(this).parents('article').remove();
        });

    });

HTML

<article class="col100 left bggreen">
    <table>
        <tr>
            <th>
                ID
            </th>
            <td>
                <input type="number" id="id">
            </td>
        </tr>
        <tr>
            <th>
                Menu in NPL
            </th>
            <td>
                <input type="text" id="menunep"></input>
            </td>
        </tr>
        <tr>
            <th>
                Menu in ENG
            </th>
            <td>
                <input type="text" id="menueng"></input>
            </td>
        </tr>
        <tr>
            <td class="cursorpointer" colspan="2" id="AddMoreId">Add field
            </td>
        </tr>
    </table>
</article>

最佳答案

对于动态添加的元素,请使用以下内容:

$(document).on('click', '#remove', function(){ 
    $(this).parents('article').remove();
});

关于jquery - 通过 jquery 添加的 css id 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50351859/

相关文章:

jquery - 如何使用 jQuery 展开文本?

jquery - Webfont 在某些窗口大小下被截断

css - IE9边框颜色错误?

JQuery 下拉位置绝对底部

CSS 转换不是像素完美的

jquery - 如何在不将 &quot 转换为 "的情况下获取元素的内容?

jquery - 使用 mixitup2 过滤会导致底部跳转

javascript - 如何将输入值传递给ajax

html - svg 阴影没有出现

jquery - 双向自动图像拉伸(stretch)/挤压/裁剪