javascript - ajax请求后替换其他东西?

标签 javascript jquery ajax

我有这个html:

<a href="#" class="cancel" id="cancel_3'">cancel</a>

当用户单击取消时,我想删除超链接,并且我想用图像替换它,即

$.ajax({
        context:this,
        type: "POST",
        url: "actions/cancel.php",
        data: "id=" + the_id,
        cache: false,
        success: function() {

            $(this).remove;
         // add image 

谢谢:))

最佳答案

尝试:

success: function() {
  $( "a#cancel_3" ).replaceWith( "<img...>" );
}

您必须在replaceWith 函数中填写您想要替换链接的内容。只是我使用的占位符。

关于javascript - ajax请求后替换其他东西?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4973615/

相关文章:

javascript - 用于扫描特定数量的重复字符的正则表达式

javascript - Node.js 中 util.format() 的补充函数

jquery - Primefaces 6.0 对话框架和框架集

html - Vue v-html 指令不运行 &lt;script src =".."> 标签

javascript - .done ajax 给我一个错误

javascript - 在 iframe 中打印整个 HTML 页面,包括 pdf 文件

javascript - setInterval() 浏览器队列

javascript - 悬停不识别图像

jquery - 创建 Python 代码来为 jQuery 数据表提供 json 数据

jquery - 如何获取两个事件 Twitter Bootstrap 选项卡的名称?