Jquery点击弹窗外关闭弹窗

$(document).ready(function(){  

            //页面初始化时隐藏弹窗  

            $('#popupWindow').hide();  

              

            //窗口外点击事件  

            $(document).click(function(e){  

                var popup = $("#popupWindow");  

                //判断事件对象不是弹窗对象  并且  弹窗对象不包含事件对象  

                if (!popup.is(e.target) && popup.has(e.target).length == 0) {  

                    //则隐藏弹窗  

                    popup.hide(500);  

                 }    

            });  

              

            $("#popBtn").click(function(e){  

                //阻止事件冒泡,防止波及本按钮  

                e.stopPropagation();  

                //显示弹窗  

                $('#popupWindow').show(500);  

            });  

              

            $("#popClzBtn").click(function(e){  

                //阻止事件冒泡,防止波及本按钮  

                e.stopPropagation();  

                //隐藏弹窗  

                $('#popupWindow').hide(500);  

            });  

        });

猜你喜欢

转载自blog.csdn.net/leo_shire/article/details/80854000