你的代码本身存在一个问题,样式应该是 div 而不是.div 因为没有class为div的标签<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $(".btn").click(function(ev){
$(".xs_div").show();
return false;
})
$(".xs_div").click(function(ev){
return false;
})
$(document).click(function(){
$(".xs_div").hide();
});
});
</script>
<style>
*{
margin:0;
padding:0;
}
div{
width:200px;
height:200px;
position:absolute;
top:50px;
left:100px;
background:#00BCF3;
display:none;
}
</style>
</head><body>
<input class="btn" type="button" value="点击"/>
<div class="xs_div"></div>
</body>
</html>

解决方案 »

  1.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
    <script type="text/javascript">
        if (window.HTMLElement && !HTMLElement.prototype.contains) HTMLElement.prototype.contains = function (o) { if (o == this) return true; while (o = o.parentNode) if (o == this) return true; return false; }
        $(document).ready(function () {
            $(".btn").click(function (e) {
                e.stopPropagation();
                $(".xs_div").toggle();
            })
        }).click(function (e) {
            if (!$(".xs_div")[0].contains(e.target)) $(".xs_div").hide();
        });
    </script>
    <style>
    *{
        margin:0;
        padding:0;
        }
    .xs_div{
        width:200px;
        height:200px;
        position:absolute;
        top:50px;
        left:100px;
        background:#00BCF3;
        display:none;
        }
    </style>
    </head>
     
    <body>
    <input class="btn" type="button" value="点击"/>
    <div class="xs_div"></div>
    </body>
    </html>