繁体   English   中英

我想使用Bootstrap Modal按钮在click事件中返回结果

[英]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
  1. jQuery没有confirm()函数,因此您正在使用浏览器的内置函数或某些插件...

  2. 您不会从自定义confirm函数中返回任何内容。 您正在定义可能最终返回值的事件处理程序,但是它们在被调用之前不会返回任何值。

很难弄清楚该函数应该做什么。 您能用英语总结一下逻辑吗?

这是您的代码现在正在执行的操作:

当用户调用内置的confirm功能时,

  1. 显示模式对话框

  2. 将其标题设置为message参数

  3. 什么都不做的权利,但附加一个onclick事件处理程序confirm类。

  4. 现在什么也不做,但是将一个onclick事件处理程序附加到cancel类。

  5. 现在什么也不做,但是将onclick事件处理程序附加到close类。

那时对这些事件处理程序执行任何有用的操作为时已晚,并且您将永远看不到它们的返回值。

如果您发布HTML并逐步说明要事件发生的顺序,人们会有所帮助。 但是否则我不确定如何。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM