[英]I want to use Bootstrap Modal buttons to return results on click event
我的目的是用`function覆蓋jquery Confirm confirm()
函數
confirm(message){
//There is a modal opened already
$('#confirm').modal('show', {backdrop: 'static'}); //Show second modal on top of the first modal
$('#confirm').find('.modal-title').html(message);
$('.confirm').on('click',function(){ //on Confirm button click of the second modal
$('#confirm').removeClass('fade').modal('hide');//Hide the Second modal
$('.page-body').addClass('modal-open'); // Addig back modal-open class to body element to prevent modal conflict
callback(); //some suggested this but it doesnt work
return true; //I want to return this to the function called this function but i get no results
});
$('.cancel').on('click',function(){
$('#confirm').removeClass('fade').modal('hide');
$('.page-body').addClass('modal-open');
callback();
return false;
});
$('.close').on('click',function(){
$('#confirm').removeClass('fade').modal('hide');
$('.page-body').addClass('modal-open');
callback();
return 'cancel';
});
}` I am not getting any results when I call the function
jQuery
沒有confirm()
函數,因此您正在使用瀏覽器的內置函數或某些插件...
您不會從自定義confirm
函數中返回任何內容。 您正在定義可能最終返回值的事件處理程序,但是它們在被調用之前不會返回任何值。
很難弄清楚該函數應該做什么。 您能用英語總結一下邏輯嗎?
這是您的代碼現在正在執行的操作:
當用戶調用內置的confirm
功能時,
顯示模式對話框
將其標題設置為message
參數
什么都不做的權利,但附加一個onclick
事件處理程序confirm
類。
現在什么也不做,但是將一個onclick
事件處理程序附加到cancel
類。
現在什么也不做,但是將onclick
事件處理程序附加到close
類。
那時對這些事件處理程序執行任何有用的操作為時已晚,並且您將永遠看不到它們的返回值。
如果您發布HTML並逐步說明要事件發生的順序,人們會有所幫助。 但是否則我不確定如何。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.