My aim is to override the jquery confirm()
function with `function
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
doesn't have a confirm()
function, so you're either using the browser's built-in function or some plugin...
You're not returning anything from your custom confirm
function. You're defining event handlers that may eventually return values, but they won't return anything until they're called.
It's hard to figure out what this function should be doing. Can you summarize the logic in English?
Here's what it looks like your code is doing right now:
When the user calls the built-in confirm
function,
Show a modal dialog
Set its title to the message
parameter
Do nothing right now, but attach an onclick
event handler to the confirm
class.
Do nothing right now, but attach an onclick
event handler to the cancel
class.
Do nothing right now, but attach an onclick
event handler to the close
class.
It's too late to do anything useful with those event handlers at that point, and you'll never see their return values.
If you post your HTML and say step-by-step, in detail what order you want events to happen in, people can help. But otherwise I'm not sure how.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.