Javascript 多点单击“问题消除”无效

Javascript 多点单击“问题消除”无效,javascript,jquery,javascript-events,debouncing,Javascript,Jquery,Javascript Events,Debouncing,我有一个代码,如果所有的验证都正确,它会发送邮件。我只需要阻止用户多次单击它。因此,我尝试使用debounce并确认debounce正在调用我的函数,但也没有帮助。我做错了什么?当快速连续单击时,我总是让弹出窗口一个接一个地出现 var bookDiningBtnHandler = function() { Ti.API.info('book dining clicked!'); var btnContext = this, message = {}; btnContex

我有一个代码,如果所有的验证都正确,它会发送邮件。我只需要阻止用户多次单击它。因此,我尝试使用debounce并确认debounce正在调用我的函数,但也没有帮助。我做错了什么?当快速连续单击时,我总是让弹出窗口一个接一个地出现

var bookDiningBtnHandler = function() {
    Ti.API.info('book dining clicked!');
    var btnContext = this, message = {};
    btnContext.touchEnabled = false;
    hideKeyBoard();
    // Avoid overlap of keyboard with the prompt..
    removeDatePicker();
    // Avoid overlap of picker with the prompt..

    var isValidEmail = procs.checkValidEmail(email.value);
    var isIntPositive = procs.isPositiveInteger(guest.value);
    //var isValid = false;
    if (name.value != '' && isValidEmail != false && isIntPositive != false && guest.value > 0 && date.text != 'Date' && time.text != 'Time') {
        if (guest.value > guestLimit) {
            message = {
                "ref" : 0,
                "title" : "Attention",
                "text" : "Booking for more than 6, please check!"
            };
            customAlert(message);
            btnContext.touchEnabled = true;
            return;
        }           
        booking = {
            "action" : "diningBook",
            "emailReservations" : Alloy.Globals.data.dining.emailReservation,
            "name" : name.value,
            "email" : email.value,
            "guest" : guest.value,
            "date" : date.text,
            "time" : time.text
        };

        procs.sendEmail(booking, function(e) {
            treatTheAnswer(e);              
            customAlert(message);
            btnContext.touchEnabled = true;
        });
        function treatTheAnswer(resultSentEmail) {
            if (resultSentEmail) {
                message = {
                    "ref" : 0,
                    "title" : "Booking sent",
                    "text" : "A member of our team will contact you to confirm your booking"
                };
            } else {
                message = {
                    "ref" : 1,
                    "title" : "Error ",
                    "text" : "Something went wrong. Please try again later!"
                };
            }
        }

    } else {

        message = {
            "ref" : 0,
            "title" : "Missed info",
            "text" : "Missing information, Please fill in all fields!"
        };
        if (!isValidEmail && isIntPositive) {
            message = {
                "ref" : 1,
                "title" : "Error",
                "text" : " Invalid Email Address. Please re-enter valid Address!"
            };
        }
        customAlert(message);
        btnContext.touchEnabled = true;
    }
};

function debounce(func, wait, immediate){   
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
var timeout = null;
return function() {
    var context = this, args = arguments;
    clearTimeout(timeout);
    timeout = setTimeout(function() {
        timeout = null;
        if (!immediate)
            func.apply(context, args);
    }, wait);
    if (immediate && !timeout)
        func.apply(context, args);
};  
};
v6.addEventListener('click', procs.debounce(bookDiningBtnHandler, 1000));

您能在JSFIDLE中创建一个更简单的示例吗?只是为了证明这个问题。在分配它之前,您不能使用
bookDiningBtnHandler
!阅读@Bergi you's right..我在粘贴代码时出错了..然后请你的问题来解决它。到底是什么不起作用?