【发布时间】:2013-11-09 00:20:06
【问题描述】:
我尝试了Chinnu R的方法,但是当我点击div外的任何地方时,菜单项不会隐藏,只有当我点击div内部时,菜单项才会隐藏,我想要相反,即点击div外,隐藏,点击里面div,别动。
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function() {
$("button").click(function() {
$('div#nomore').toggle();
});
$("body > *").not("body > button").click(function(e) {
$('div#nomore').hide();
});
});
</script>
</head>
<body>
<button>MENU</button>
<div id="nomore" style="display:none; background-color:yellow; width:300px;">
<br>
<a href="www.yahoo.com">Yahoo</a><br>
ITEM 2<br>
ITEM 3<br>
ITEM 4<br>
ITEM 5<br>
</div>
</body>
</html>
【问题讨论】:
-
检查这个 jsfiddle,我认为 rhis 会解决你的问题。 [1]:jsfiddle.net/jc7xA/1
标签: jquery