1

当我在我的对话框上调用 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
4

1 回答 1

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. 
于 2013-09-03T18:20:27.027 回答