$(this).parent().remove()不起作用

Nat*_*hat -3 html javascript jquery

即使这是" 事件处理程序不处理动态内容 " 的重复问题,即使按照那里给出的答案,我仍然遇到同样的问题.请帮忙 ....

    userinfo.topics.forEach(ele=>{
            $("#topics_subscribed").append(`<li class="list-group-item col-4">${ele} &nbsp;<i style="color:red;font-size:.7em;" class="removeitem fa fa-times"/></li>`) ;
        });


    $(document).on('click', '.removeitem', ()=> {
        console.log('clicked') ; 
        $(this).parent().remove() ; 
    });
Run Code Online (Sandbox Code Playgroud)

请在将此标记为重复之前回答其原因.如何解决这个问题?(我会在答复后立即删除这个问题....)

cha*_*tfl 5

这是因为你使用的箭头函数没有明确的 this

改成:

$(document).on('click', '.removeitem', function(){
    console.log('clicked') ; 
    $(this).parent().remove() ; 
});
Run Code Online (Sandbox Code Playgroud)