首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >为什么jquery对话框不能完全实现fadeOut()呢?

为什么jquery对话框不能完全实现fadeOut()呢?
EN

Stack Overflow用户
提问于 2013-09-01 16:06:35
回答 1查看 178关注 0票数 1

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

代码语言:javascript
复制
//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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-09-03 18:20:27

好吧我想明白了。我去掉了对话框init代码中的beforeClose参数,并在表单验证提交处理程序中添加了以下内容:

代码语言:javascript
复制
 $('#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. 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18560276

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档