colorbox关闭确认

时间:2010-09-21 17:23:28

标签: jquery colorbox

$(document).ready(function(){
$('#rest').colorbox();
$("#cboxClose").click(function(){ $.fn.colorbox.close(); });
var cboxClose = $.fn.colorbox.close;
$.fn.colorbox.close = function(){ if(confirm("Are you sure?")) { cboxClose(); } }
});

当我确认对话框时,此代码关闭了我的jquery颜色框,但是如果我点击取消(!确认)它关闭

我做错了什么?

1 个答案:

答案 0 :(得分:1)

我认为这可以做得更简单

$(function(){

    $('#rest').colorbox();

      // If close button is clicked...
    $("#cboxClose").click(function(){ 

          // Confirm desire to close, and only close if confirmed
        if(confirm("Are you sure?")){ $.colorbox.close(); };
    });

});

注意:
$(function() { ... }); is synonymous with $(document).ready(function() { ... });