0
我想重寫刪除上傳文件時Dropzone處理確認對話框的默認方式,我幾乎達到了某種程度。這是我的代碼。如何使用自定義確認對話框允許使用dropzone刪除多個上傳的文件?
Dropzone.confirm = function(question, accepted, rejected) {
showConfirm(question);
$(document).on('click', '#accept-confirm', function() {
hideConfirm();
accepted();
});
}
showConfirm = function(question) {
var confirm_dialogue = '<div id="confirm-dialogue"><span class="question">'+question+'</span><button id="deny-confirm" class="button">Cancel</button><button id="accept-confirm" class="button">Yes</button></div>';
$('body').append(confirm_dialogue).addClass('is-showing-confirm');
}
hideConfirm = function() {
$('body').removeClass('is-showing-confirm');
let dialogue = document.getElementById('confirm-dialogue');
dialogue.parentNode.removeChild(dialogue);
}
我可以點擊我的刪除按鈕,我的自定義確認顯示。我可以確認刪除並刪除縮略圖。
問題是我只能爲一個圖像做到這一點。對於我想刪除的任何其他圖像,我只是在控制檯中出現以下錯誤。
Uncaught TypeError: Cannot read property 'removeChild' of null
第一個答案的作品,將關閉之前。我不完全理解你應用於按鈕的事件被稱爲多次的意思,但它確實有效。第二個失敗是因爲在Dropzone.confirm之外,接受的()回調不可用。謝謝 –
我的意思是,第一次當你的Confirm函數調用你的'accept-confirm'時,單擊事件綁定到DOM,並且每當你確認函數調用時它就會一次又一次地綁定它。所以在單個元素上添加了多個點擊事件。這就是爲什麼你的'hideConfirm'一次又一次地調用這會導致'removeChild'的問題。 –