jquery 中的 .remove() 不会立即删除 DOM

.remove() in jquery doesn't remove DOM instantly

本文关键字:删除 DOM 中的 remove jquery      更新时间:2023-09-26

我有以下函数来删除DOM元素"div",

$('#emDiv').on("click", ':button[data-emp-del="true"]', function (evt) {
        evt.preventDefault();
        // Get Row - "emp0" or "emp1" etc ...
        var rowId = "#" + $(this).data('emp-id');
        // Remove the DIV
        $(rowId).fadeOut('normal', function () {
            $(this).remove();
        });
        // The results below returns even the one that was removed
        // $('div[id^="emp"]')
        return false;
    });

如何立即完全删除上面的 DIV,因为我想循环剩余的 DIV 更改其 ID。

谢谢

剩磁代码也放在淡出回调函数中。javascript语句异步执行,这就是你得到元素的原因。相反,您的元素会在 1 秒后删除。