當我點擊「菜單」,「.submenu」切換,我需要當我點擊之外,那麼「.submenu」應該隱藏。我已經在每個div中像使用行一樣使用它,就像我們在應用程序中使用它放置在右側以進行編輯刪除一樣。 在此先感謝。外點擊隱藏元素
HTML:
<div class="edit-goal-wrapper">
<div class="dropdown">
<a class="account" >Menu</a>
<div class="submenu">
<ul class="root">
<li ><a href="#" >Edit Target Date</a></li>
<li ><a href="#" >Remove Goal</a></li>
</ul>
</div>
</div>
</div>
CSS:
.edit-goal-wrapper .dropdown
{
color: #555;
margin: 0;
right: 30px;
text-align: left;
}
.edit-goal-wrapper .submenu
{
background: #fff none repeat scroll 0 0;
border-radius: 6px;
-webkit-box-shadow: 0 0 8px rgba(0, 0, 0, 0.1);
-moz-box-shadow: 0 0 8px rgba(0, 0, 0, 0.1);
box-shadow: 0 0 8px rgba(0, 0, 0, 0.1);
position: absolute;
right: 5px;
top: 0px;
z-index: 100;
width:150px;
display:none;
}
.edit-goal-wrapper .dropdown li a
{
color: #555555;
display: block;
font-family: arial;
font-weight: normal;
padding: 6px 15px;
cursor: pointer;
text-decoration:none;
}
.edit-goal-wrapper .dropdown li a:hover
{
background:#155FB0;
color: #FFFFFF;
text-decoration: none;
}
.edit-goal-wrapper a.account
{
background: rgba(0, 0, 0, 0) url("icons/arrow.png") no-repeat scroll 116px 17px;
color: #555;
cursor: pointer;
display: block;
font-size: 30px;
/*height: 28px;*/
text-decoration: none;
z-index: 110;
}
.edit-goal-wrapper .root
{
border-top: 1px solid #dedede;
font-size: 12px; font-weight:normal;
list-style: outside none none;
margin: 0;
padding: 4px 0 2px;
}
的jQuery:
$(".edit-goal-wrapper a").click(function(){
$(this).next().toggle();
});
還可以看到這個https://www.script-tutorials.com/click-action-css3-dropdown-menu -with-jquery/ –