从$(this)块内调用的Boombox没有显示 - 除此之外没有任何问题

时间:2014-11-22 07:29:28

标签: jquery function this bootbox

我正在尝试从$(document).ready块内显示一个bootbox。 这显示正常,直到我将调用函数的行放在$(this)块中。 什么阻止这种工作的想法?

我有以下代码:

    $(document).ready(function()
    {
        var getID = '#removeEntryCourses';


        $(this).on('click', getID, function () 
        {
            bootDialogSuccess('<h2>Are you sure?</h2>', 'Are you sure you want to delete this course?<br/>This cannot be undone.');
        });

        //bootDialogSuccess('<h2>Are you sure?</h2>', 'Are you sure you want to delete this course?<br/>This cannot be undone.'); 
        //When this line is uncommented and the $(this) block is removed there is no issue.

    });

    function bootDialogSuccess(title, message)
    {
        bootbox.dialog
        ({  
            message: message,
            title: title,
            buttons: 
            {
                success: 
                {
                    label: "OK",
                    className: "btn-success",
                    callback: function() 
                    {
                        alert('hello');
                        //removeCourse(total);
                    }
                }
            }
        });
    }

1 个答案:

答案 0 :(得分:0)

因此,在函数调用之后问题的罪魁祸首是return false

    $(this).on('click', getID, function () 
    {
        bootDialogSuccess('<h2>Are you sure?</h2>', 'Are you sure you want to delete this course?<br/>This cannot be undone.');

        return false;
    });

但是我不确定为什么当jsfiddle在评论中发布时这不会导致问题。