0

我有多个隐藏可见性的菜单(表单),我用图标上的点击事件打开它们。一切都很好,除了当我打开另一个菜单时前一个菜单仍然打开时,它们都保持可见。所以,我希望在打开新菜单时隐藏前菜单。

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();
}
4

2 回答 2

0

问题出在这条线上

if($(document).find(".settingForms").is(':visible') < 1)

不需要< 1,你可以使用

if($(document).find(".settingForms").is(':visible'))
于 2012-11-07T09:37:55.677 回答
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();
}​
于 2012-11-07T09:35:15.047 回答