Click on empty space to close the popup

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>点击空白处关闭弹窗</title>
<script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
<style>
.box {
margin:50px auto;
width:100px;
height:100px;
background-color:pink;
}
</style>
</head>
<body>
<div class="box"></div>
<script>
click("box","box");
function click(name,box) {
    $(document).on("click", function(e) {
        var _conss = $('.'+name);//Clicked container range
        if (!_conss.is(e.target) && _conss.has(e.target).length === 0) {
            $("."+box).hide();//Select the container to close
        }
    });
}
</script>
</body>
</html>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324728336&siteId=291194637