【发布时间】:2019-08-29 20:18:33
【问题描述】:
我正在尝试在更改其类后 500 毫秒删除元素“this”,但它不起作用
$('.card').click(function() {
setTimeout(function(){
$(this).remove();
console.log('removed');
},500);
$(this).toggleClass("card card-used");
});
和 HTML
<div class="card">asdasd</div>
我可以在控制台日志中看到“已删除”,但不是 remove()
【问题讨论】:
-
this存在于 click 函数中,而不是您传递给 setTimeout 的函数中。 -
为了扩展我上面的评论,
thision 你的例子是指窗口对象