为什么我的jquery对话框不会完全fadeOut()?

时间:2013-09-01 16:06:35

标签: jquery-ui jquery-ui-dialog

当我在对话框中调用fadeOut时,它只会进行部分淡入淡出并留下对话框标题所在的灰色标题区域。我已经尝试删除标题以及禁用对话框右上角退出按钮的各种属性,但这不起作用。正如您在下面的脚本中看到的那样,我希望在验证表单提交后关闭对话框。

//HTML
 <div id="dialog"> 
     <form id="form">

         <p id="thanks">Please provide a contact number. It will only be shared with the 
host</p><input id="number" name="number" type="text"/>

    <button id="submit" type="submit">Submit</button>

 </form>

 </div>

//JS
 if(myConditional){

            //FORM IS HIDDEN ON PAGE LOAD AND SHOWN ON CLICK  

            $('form').show();

            $('#dialog').dialog({

//These parameters are meant to disable the dialog close button

    closeOnEscape: false,
   beforeclose: function (event, ui) { return false; },
   dialogClass: "noclose",
   title: "Thanks For Volunteeering",
   minWidth: 500

});
            $('button').button();

        }else{
           //other code
        }

 //Validate the phone number before saving it to local storage   

     $("#form").validate({
            rules: {
                  number : {
                    required: true
                    customvalidation: true
                }                                        
            },
            messages: {
                number : {
                    required: "enter a phone number"                   
                }
            },
            submitHandler: function(form) {

                   var number = $('#number').val();

localStorage.setItem('number', JSON.stringify(number));



                    //THIS FADE OUT ISN'T FULLY FADING THE DIALOG

                     $('#dialog').fadeOut();

            }  //closes submit handler  
        });//close validate

1 个答案:

答案 0 :(得分:0)

好的我明白了。 我在对话框初始化代码中删除了 beforeClose 参数,并在表单验证提交处理程序中添加了这个:

 $('#dialog').fadeOut('slow', function(){
                        $( this ).dialog( "close" );

                    });

//The fadeOut method has a call back function you can use with it to do something after the fade is completed.