jQuery ajax成功$(this)后无法正常工作

阿拉古

我是js和jquery的新手,请为我提供帮助,问题是:

$(this).html('<span class="label label-success icon-fontawesome-webfont-11"> Paid</span>');

不管用。

window.onload = function() {
    $(".myclass").click(function(){
        var current_id = this.id;
            $.ajax({
                type: "POST",
                url: "/ajax.php",
                data:'current_id='+ current_id
           }).done(function(result) {
                $(this).html('<span class="label label-success icon-fontawesome-webfont-11"> Paid</span>');
          });
    });
}
Sudhir Bastakoti

尝试添加context,例如:

window.onload = function() {
    $(".myclass").click(function(){
        var current_id = this.id;
            $.ajax({
                type: "POST",
                context: this, //add this
                url: "/ajax.php",
                data:{current_id : current_id},
           }).done(function(result) {
                $(this).html('<span class="label label-success icon-fontawesome-webfont-11"> Paid</span>');
          });
    });
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章