Js删除类不起作用

时间:2018-08-14 09:11:20

标签: javascript html json ajax

我有一个button,点击后可以使用js添加类,效果很好。

它应该删除任何AJAX响应上的类。 我叫removeclass(),但它不会删除旋转。

我已经检查了代码,并在此论坛中通过了其他几种解决方案,但未成功。 我将不胜感激。

$(".btn-take").click(function(e) {
    e.preventDefault();

    var name = $(this).attr("data-name");
    var that = $(this);

    that.addClass("disabled");
    that.html('<i class="fa fa-circle-o-notch fa-spin"></i>');

    // Activate purchase
    $.ajax({
        url: base_url + "premium/activate_feature",
        type: 'POST',
        data: {name : name},
        success: function(data) {
            if(data.result == 999) {
                alert("You are not logged in anymore");
                window.location = base_url;
            } else if(data.result == 998) {
                alert("Error, this premium feature doesn't exist.");
                that.removeClass("disabled");
            } else if(data.result == 997) {
                $(".alert-purchase").removeClass("alert-success").addClass("alert-danger").html(not_enough_credits_str).fadeIn();
                that.removeClass("disabled").html("<i class='fa fa-diamond'></i> " + take_it_str);
                scrollTopToStatus();
            } else {
                if(name == "see_who_loves_you") {
                    $(".alert-purchase").html("see_loves_success_str");
                } else if(name == "browse_invisibly") {
                    $(".alert-purchase").html(invisible_success_str).fadeIn();
                } else if(name == "featured_one_week") {
                    $(".alert-purchase").html(featured_one_week_success_str).fadeIn();
                } else if(name == "featured_one_month") {
                    $(".alert-purchase").html(featured_one_month_success_str).fadeIn();
                }

                scrollTopToStatus();

                that.removeClass("btn-danger").addClass("btn-success").html("Success!");
            }
        }
    });
});

HTML

<div class="pf_take_it col-md-2">
    <?php if($loves_purchased): ?>
       <a class="btn btn-success disabled">
           <i class="fa fa-check"></i> <?php echo $this->lang->line("purchased_btn"); ?>
       </a>
    <?php else: ?>
       <a class="btn btn-danger btn-take" data-name="see_who_loves_you">
           <i class="fa fa-diamond"></i> <?php echo $this->lang->line("take_it_btn"); ?>
      </a>
    <?php endif; ?>
 </div> 

1 个答案:

答案 0 :(得分:0)

尝试一下

that.classList.remove('disabled');