【问题标题】:jQuery, allow only once to click on dialogue yes buttonjQuery,只允许点击一次对话是按钮
【发布时间】:2016-07-16 07:42:21
【问题描述】:

我正在尝试编写一个 jQuery 对话框,当我单击“确定”按钮时,每次单击它都会发送数据。

因此,无论是多次单击还是单击“确定”按钮一次,我都需要它只工作一次。

$.dialogue({
                    class: 'big',
                    body: html,
                    yes: {
                        text: 'ok',
                        func: function() {

                            //execute some codes

                    }, //end function
                    },
                    no: {text: 'Cancel'},
                });

【问题讨论】:

  • 你从哪里得到“$.dialogue”插件的?
  • 你有一个var checker = true; put your code inside if(checker){//code here checker= false;}
  • 取决于插件,它会将this 作为被点击的按钮或对话框本身传递。如果是按钮,您可以这样做:func: function() { $(this).hide();(或禁用它,取决于它如何创建“按钮”)。
  • 或者只是添加一个标志if (clicked) return; clicked=true;
  • 现在它正在发布我点击次数的数据\/_\/

标签: javascript jquery jquery-ui jquery-plugins jquery-ajaxq


【解决方案1】:
$.dialogue({
                    class: 'big',
                    body: html,
                    yes: {
                        text: 'ok',
                        func: (function() {
                            var executed = false;
                            return function () {
                            if (!executed) {
                            executed = true;
                            //execute some codes                                                            
                        }
                        };
                    })(), //end function
                    },
                    no: {text: 'Cancel'},
                });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-21
    • 2020-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多