顯示/隱藏問題的工作完全正常。我可以點擊#business打開我的菜單,在關閉菜單的元素'html'外單擊,或者再次單擊#business。這個CSS/jQuery的組合
問題1:#business不會恢復到#323232。
問題2:如果我點擊了新的菜單(#businessmenu)jQuery的隱藏它,裏面我怎麼能只通過點擊元素或#business切換外面躲呢?
的JavaScript:
$("#business").click(function(event){
jQuery.fx.off = true;
$("#businessmenu").toggle("");
$(this).css("background-color", "#000");
event.stopPropagation();
});
$('html').click(function() {
$("#businessmenu").hide();
$("#business").css("background-color", "#323232");
});
CSS:
header {
float: left;
background: #323232;
width: 98%;
padding: 0 1%;
color: #E9F1F4;
}
header a {
color: #e9f1f4;
font-size: 20px;
font-weight: bold;
}
header a:hover {
background: #000;
color: #fff;
}
header #business {
float: left;
position: relative;
padding: 10px 35px 13px 20px;
}
#businessmenu {
display: none;
background: #000;
width: 220px;
height: 200px;
position: absolute;
top: 60px;
left: 1%;
border-radius: 0 0 6px 6px;
padding: 10px 35px 13px 20px;
}
HTML:
<a href="#" id="business">Name</a>
<div id="businessmenu">
<a href="help.html">Help</a>
</div>
嘗試設置一個http://jsfiddle.net – 2012-02-15 00:12:51