jQuery html()不会覆盖当前的html

 黄俊毅伶云政星 发布于 2023-02-13 13:30

好的,这是我的jQuery:

$.ajax({
    type: "POST",
    url: $(this).attr('href')
}).done(function( msg ) {
    $(this).parent().closest('p').html('Image Removed');
});

这是我的HTML:


自数据库更改以来,ajax工作正常.但是,完成功能无法正常工作.

我提醒了$(this).parent().closest('p').html()它,它会提醒div当前的html.但是,它不会覆盖我正在输入的'Image Removed'.

1 个回答
  • this 在done函数内部不是元素,因为有一个新的函数范围

    var elem = this;
    
    $.ajax({
        type: "POST",
        url: $(this).attr('href')
    }).done(function( msg ) { // new function scope, "this" is now the XHR function
        $(elem).parent().closest('p').html('Image Removed');
    });
    

    2023-02-13 13:32 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有