Jquery UI模式对话框无法正常工作

时间:2012-04-29 06:20:17

标签: jquery-ui

我找到一种让jquery ui模态对话框工作的方法很麻烦。模态对话框只返回false ...

你可以在这里找到一个小提琴http://jsfiddle.net/fVrFj/6/

    function modal_delete_pics(){
            $(function(){
              $( "#dialog:ui-dialog" ).dialog( "destroy" );

              $( "#dialog-confirm" ).dialog({
                resizable: false,
                height:140,
                modal: true,
                buttons: {
                    "delete": function() {
                       $( this ).dialog( "close" );

                                     return true;
                },
                    "cancel": function() {
                        $( this ).dialog( "close" );
                        return false;

                }
            }

        });
    });
};
    $('#clickme').click(function(){
        if(modal_delete_pics()==true){
           $('body').append('<div>deleted</div>');  
           }
          else{                   
             $('body').append('<div>canceled</div>');
              }
});

非常感谢!

1 个答案:

答案 0 :(得分:4)

你在另一个函数($( "#dialog-confirm" ).dialog)中的函数($(function())中有一个函数(function modal_delete_pics())。

并且,最里面的函数($( "#dialog-confirm" ).dialog)的返回值不会冒出来。

你可以尝试一种更简单的方法:

$("#dialog-confirm").dialog({
        resizable: false,
        height: 140,
        modal: true,
        autoOpen: false,      
        buttons: {
            "delete": function() {
                //put your image delete code here
                $('body').append('<div>deleted</div>');
                $(this).dialog("close");
            },
            "cancel": function() {
                $('body').append('<div>canceled</div>');
                 $(this).dialog("close");
            }
        }
});

$('#clickme').click(function() {
    $("#dialog-confirm").dialog("open");
});​

小提琴:http://jsfiddle.net/fVrFj/10/

相关问题