我有多个隐藏可见性的菜单(表单),我用图标上的clickevent打开它们。这一切都很好,当我打开另一个菜单时,当前一个菜单仍然打开时,它们都保持可见。因此,我想要在新的菜单打开时隐藏fomer菜单。
HTML
<span id='settingsIcon' class='settingsIcon'>S
<div class='settingForms'>
<div class='formMoveButton'>
<span class='settingsMakePublicIcon'>w</span>
<form action='' method='post' class='moveForm'>
<input class='settingsMakePublicButton' type='submit' value='Make public ' name='$this->move'/>
</form>
</div>
</div>
</span>
的jQuery
$(".settingsIcon").click(function(event) {
event.stopPropagation();
if($(document).find(".settingForms").is(':visible') < 1) {
HandleSettingsWindow($($(this).children()[0]));
} else {
}
});
HandleSettingsWindow = function (el) {
$(document).click(function () { // Close the menu when clicked outside it
el.hide();
document.oncontextmenu = function () { return true; };
});
el.toggle();
}
答案 0 :(得分:0)
请试试:http://jsfiddle.net/RttT5/
注意 if($(document).find(".settingForms").is(':visible'))
希望休息满足您的需求:)
<强>代码强>
$(".settingsIcon").click(function(event) {
event.stopPropagation();
if($(document).find(".settingForms").is(':visible')) {
HandleSettingsWindow($($(this).children()[0]));
} else {
}
});
HandleSettingsWindow = function (el) {
$(document).click(function () { // Close the menu when clicked outside it
el.hide();
document.oncontextmenu = function () { return true; };
});
el.toggle();
}
答案 1 :(得分:0)
问题在于这一行
if($(document).find(".settingForms").is(':visible') < 1)
不需要&lt; 1,你可以使用
if($(document).find(".settingForms").is(':visible'))