【问题标题】:materialize disabled button not working on jquery ajax物化禁用按钮不适用于jquery ajax
【发布时间】:2016-11-04 00:46:25
【问题描述】:

,我正在尝试禁用实现按钮,当它被点击时......但它对我不起作用,在我的 ajax 请求的成功功能上,它必须添加从此框架禁用的类......但没有发生了,并且 ajax 请求它工作正常!!...请帮助!!

$(document).on('click', '.aprove , .disapprove', function() {
    if (sesion != "") {
        if ($(this).attr('class').split(' ').pop() == 'aprove_president') {

            var id = $(this).closest("div .col .s6").find('input[type=hidden]').attr('id');
            alert(id);
            var data = {

                'id_politic' : id,
                'sesion'     : sesion,
                'status'     : 1
            }

            $.ajax({
                url: baseurl+'result/aprove',
                type: 'POST',
                data: data
            })
            .done(function() {
                $(this).addClass('disabled');
            })
            .fail(function() {
                console.log("error");
            })
            .always(function() {
                console.log("complete");
            });

        }
        else if ($(this).attr('class').split(' ').pop() == 'disapprove_president') {

        }

    }
    else {
        $('#verification').openModal();
    }
});

【问题讨论】:

  • 是的!而已 !!谢啦 !请发布您的答案,这样我就可以正确选择它!

标签: jquery ajax button materialize


【解决方案1】:

$(this) 在您的 done 匿名函数中处于不同的范围内。因此,这不是您的按钮。

你可能想这样做,

$(document).on('click', '.aprove , .disapprove', function() {
    var $btn = $(this);

并在您的done 中重复使用它,

.done(function() {
   $btn.addClass('disabled');
})

【讨论】:

    猜你喜欢
    • 2015-01-03
    • 1970-01-01
    • 2018-11-03
    • 2019-10-14
    • 1970-01-01
    • 1970-01-01
    • 2018-05-17
    • 1970-01-01
    • 2019-03-08
    相关资源
    最近更新 更多