jquery点击div之外的地方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>

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

</head>

<body style="background:black;width:100%;height:100%;margin:0;padding:0">

    <div id="showdiv" style="background:white">click here to show a div.</div>

    <div id="test" style="background:white;width:150px;height:150px;">

        <ul>

   <li>list 1</li>

   <li>list 2</li>

        </ul>

</div>

</body>

<script type="text/javascript">

$(function() {

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

e?e.stopPropagation():event.cancelBubble = true;

});

$(document).click(function() {

$("#test").fadeOut();

});

})

</script>

</html>

相关推荐