[英]I want to use Bootstrap Modal buttons to return results on click event
My aim is to override the jquery confirm()
function with `function 我的目的是用`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
doesn't have a confirm()
function, so you're either using the browser's built-in function or some plugin... jQuery
没有confirm()
函数,因此您正在使用浏览器的内置函数或某些插件...
You're not returning anything from your custom confirm
function. 您不会从自定义
confirm
函数中返回任何内容。 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, 当用户调用内置的
confirm
功能时,
Show a modal dialog 显示模式对话框
Set its title to the message
parameter 将其标题设置为
message
参数
Do nothing right now, but attach an onclick
event handler to the confirm
class. 什么都不做的权利,但附加一个
onclick
事件处理程序confirm
类。
Do nothing right now, but attach an onclick
event handler to the cancel
class. 现在什么也不做,但是将一个
onclick
事件处理程序附加到cancel
类。
Do nothing right now, but attach an onclick
event handler to the close
class. 现在什么也不做,但是将
onclick
事件处理程序附加到close
类。
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. 如果您发布HTML并逐步说明要事件发生的顺序,人们会有所帮助。 But otherwise I'm not sure how.
但是否则我不确定如何。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.