【问题标题】:Enable / Disable button (Bootstrap 3) using jQuery使用 jQuery 启用/禁用按钮 (Bootstrap 3)
【发布时间】:2014-11-16 03:40:36
【问题描述】:

我有一个使用 Bootstrap3 样式的按钮,不确定这是否真的重要......

<button type="button" class="btn btn-danger" disabled="disabled" id="transmitDirectMail">Send</button>

我有一个 jquery ajax,它验证输入并在值是有效的 Direct Mail 时启用/禁用按钮。

$("#directMailAddress")
    .keyup(function () {
        transmitToDirectEmail = this.value;
        $.ajax({
            type: "POST",
            url: "./phiMail/ValidateDirectMail.php",
            cache: false,
            data: { dMail: transmitToDirectEmail }
        })
            .done(function( msg ) {
                if (msg = "0")
                    $("#transmitDirectMail").prop('disabled', true);;
                if (msg = "1")
                    $("#transmitDirectMail").prop('disabled', false);
            });
    });

问题是设置道具启用按钮。 ('disabled', true) 不会禁用按钮。

【问题讨论】:

    标签: javascript jquery twitter-bootstrap


    【解决方案1】:

    这是因为您使用=赋值运算符)而不是===== 进行比较。

    .done(function( msg ) {
        $("#transmitDirectMail").prop('disabled', msg == "0");
    });
    

    【讨论】:

    • 有时很简单。只是我的代码中的一个错字。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-02
    • 2010-12-08
    相关资源
    最近更新 更多