jQuery从 AJAX 中移除列表元素

xyhw6mcr  于 2023-06-22  发布在  jQuery
关注(0)|答案(1)|浏览(113)

如何删除 AJAX 查询的complete函数中的列表元素<div class="image-?">...</div>$(this) ...?

<div class="edit-image-list">
    @foreach (var image in Model.AttachedImages)
    {
        <div class="image-@image.Id">
            <img width="180" height="180" src="data:image/jpeg;base64,@(Convert.ToBase64String(image.Data))" class="img-thumbnail" alt="Responsive image">
            <a class="delete-image" data-id="@image.Id">Delete</a>
        </div>
    }
</div>

<script>
    $(document).on('click', '.delete-image', function (e) {
        e.preventDefault();

        console.log($(this).data("id"));

        $.ajax({
            method: "POST",
            url: "@Url.Action("DeleteImage","Forum")",
            error: function () {
                console.log('error');
            },
            data: { Id: $(this).data("id") },
            complete: function () {
                // How to delete class="image-?"
            }
        });
    });
</script>
uhry853o

uhry853o1#

对以image开头的div使用通配符:

$("div[class^=image]").remove()

相关问题