在上传按钮之前确认点击 Blueimp JQuery fileupload

Confirm before upload button click Blueimp JQuery fileupload

我在使用 Blueimp JQuery AJAX 文件上传插件时遇到问题。 我想要做的是将一个函数绑定到上传按钮,以便在单击上传按钮时显示确认警报。问题是我在 ajax 调用中使用了 add: 选项,这会在选择要上传的文件时添加该功能,这会导致确认消息出现 x 次用户选择要上传的文件上传。有办法解决这个问题吗?

function setUploadBtnForm1(token){
        var regexp = new RegExp("/settings$", "i");
        var url = window.location.origin + window.location.pathname.replace(regexp, '/ajaxUploadSigFile');
            $('#fileUpload').fileupload({
                formData: {_token: token},
                datatype:'json',
                url:url,
                allowedTypes:'png',
                add:function(e, data){
                            $('#signatureUploadBtn1').click(function(){
                                var response = confirm('This will remove the existing signature are you sure?');
                                if(response == true)
                                {
                                    data.submit();
                                }else{
                                    e.preventDefault();
                                }
                    });
                },
                success: function(data){
                    var query = data;
                    if (query.RESULT == 'PASS')
                    {
                        $('#signatureUploadBtn1').hide();
                        //set src attribute of signature image to filename of uploaded file.
                        $('.sigImage1').attr('src', '../images/signatures/'+query.FILENAME);
                            $('.modalLoadContent').fadeOut('fast');
                            $('.modalFinishContent').show();
                    }else{
                        $('#signatureUploadBtn1').text('Failed!');
                    }
                }
            })
    }

我现在已经成功解决了这个问题。我刚刚在添加点击事件的函数中添加了一个 unbind('click') ,如下所示:

$('#fileUpload1').fileupload({
                formData: {_token: token},
                datatype:'json',
                url:url,
                allowedTypes:'png',
                replaceFileInput:false,
                autoUpload:false,
                add:function(e, data){
                    uploadButton.unbind('click');
                    uploadButton.click(function(){
                        var response = confirm('This will remove the existing signature are you sure?');
                        if(response == true)
                        {
                            data.submit();
                        }else{
                            data.abort();
                        }
                    })
                },