【问题标题】:jquery checking select input if changed with conditionjquery检查选择输入是否随条件改变
【发布时间】:2016-07-03 18:48:22
【问题描述】:

i have this code below when the select changes it works great and check for the correct condition but then for the second time if i change the select both conditions run after each other

$('#x_Statususer').on('change', function () {       
    var chng = !this.options[this.selectedIndex].defaultSelected;
    if (chng) {
        alert("has changed");
        var celm=$( this ).val();
        if (celm== "Revision") {
            $("#btnAction").click(function() {
                var r = confirm("Are you sure you want to set to Revision! ");
                if (r == false) {
                    return false;
                }
            });
        }
        else if (celm == "Canceled") {
            $("#btnAction").click(function() {
                var r = confirm("Are you sure you want to set to Cancel! ");
                if (r == false) {
                    return false;
                }
            });
        }   
    } else {}
});

【问题讨论】:

    标签: javascript jquery if-statement input selection


    【解决方案1】:

    问题是您在每次更改时将点击事件重新绑定到#btnAction。尝试改变:

    $("#btnAction").click(function() {...});
    

    收件人:

    $("#btnAction").one(function() {...});
    

    【讨论】:

    • 非常感谢我让它像 $("#btnAction").one("click", function()
    猜你喜欢
    • 2011-06-18
    • 1970-01-01
    • 2013-11-18
    • 2011-12-05
    • 1970-01-01
    • 2014-04-18
    • 2010-12-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多