当有人在框外单击时,如何隐藏<div>
框。我找不到问题。所以请帮我解决这个问题。
<html>
<head>
<title>Test jQuery</title>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#button-upload').click(function() {
$('#id_menu_profile').show();
});
});
var $box = $('#id_menu_profile');
$(document.body).click(function(){
if (!$box.has(this).length) { // if the click was not within $box
$box.hide();
}
});
</script>
</head>
<body>
<dl>
<dt><a id="button-upload" href="#">Profile<img src="menu.png" name="arrow_profile"></a></dt>
<!-- Submenu -->
<div id="id_menu_profile" style=" display: none;">
<dt><a href="index.html">Your Id</a></dt>
<dt><a href="index.html">Account Setting</a></dt>
<dt><a href="index.html">Change Password</a></dt>
</div>
</dl>
</body>
</html>