`
axl234
  • 浏览: 258160 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

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>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics