13

我的页面上有一个 CSS 吸盘鱼侧菜单。当用户单击页面中的某个项目时,我会弹出一个 jQuery UI 对话框,并且在页面上的一个 div 中,我正在通过 jQuery AJAX 加载一个 HTML 页面。

在 Chrome 中,每当我单击菜单上的某个项目时,焦点就会从菜单转移到 jQuery UI 对话框上。

但在 IE 和 Opera 中,即使我点击了该项目,焦点仍保留在菜单上。jQuery UI 对话框无法将焦点从菜单上移开,因此它保持打开状态并挡住了用户的视线。

请看一下所附图片。

在此处输入图像描述

正如你所看到的,我什至添加了一个文本框并在那里抓住了焦点,但即便如此也没有任何变化。

根据要求,这是该网站的链接

示例:当您在 IE 9 中打开网站并单击说Technologies > MySQLTechnologies > MSSQL时,菜单不会关闭,但应该是因为我在加载后面的页面时打开了一个模式对话框分区。但是,如果您在 chrome 中打开页面并尝试相同的操作,则菜单会按原样关闭。附上相关的代码片段:-

/**********************************************
Function to load an html page inside a div
**********************************************/
function loadPageInDiv(containerDiv, pageToLoad, divToLoadIn, loadingDialog, callBackFunction) {
    var parentDiv = $("#" + containerDiv);
    var loadDiv = $("#" + divToLoadIn);
    var dialogBox = $("#" + loadingDialog);
    // Show dialog box first, then fadeOut, then load, then fadeIn,the close.
    $(dialogBox).data('loadDiv', loadDiv).dialog("open");
    $(loadDiv).load(pageToLoad, function (response, status, xhr) {
        if (response == "error") {
            $(dialogBox).dialog('close');
        }
        else {
            if (callBackFunction != null) {
                callBackFunction();
            }            
            checkAndDisplay(loadingDialog, divToLoadIn);
        }
    });
}

初始化 jquery-ui 对话框的函数。

/**************************************
Function to initialize the dialog box
*****************************************/
function initializePleaseWaitDialog() {
    $("#osmPleaseWait").dialog({
        autoOpen: false,
        modal: true,
        dialogClass: 'noTitleDialog',
        draggable: false,
        resizable: false
    });
}

切换DIV显示的功能

/***************************************
Function to toggle div display
****************************************/
function checkAndDisplay(dialogToHide, divToShow) {
    $("#" + divToShow).css('display', 'block');
    $("#" + dialogToHide).dialog("close");
}

更新#3:我尝试了另一种方法,在菜单项的单击事件中,我隐藏了所有辅助 div。

        $(".osmMenuObject,.mainCatHeaderWithoutChild").click(function () {
            // Currently Selected
            $(".osmMenuObject,.mainCatHeaderWithoutChild").removeClass("osmServiceListSelected");
            $(this).addClass("osmServiceListSelected");
            // Hiding the div**
            $(".secondaryMenuContainer").css('display', 'none');
            var pageToLoad = $(this).children("input[type='hidden']").val();
            loadPageInDiv("serviceLoadDivContainer", pageToLoad, "serviceLoadDiv", "osmPleaseWait");
            return false;
        });

然后我更新了 中的代码checkAndDisplay,以删除我之前添加的显示属性,但它仍然不起作用。

function checkAndDisplay(dialogToHide, divToShow) {
    $("#" + dialogToHide).dialog("close");
    $("#" + divToShow).css('display', 'block');
    $(".secondaryMenuContainer").css('display', '');
}

这里是页面的标记

<div class="osmListContainerSpecial">
            <div class="osmListHeader" id="osmListHeaderServices">
                Our Services
            </div>
            <div class="mainCatHeader">
                Software Development
            </div>
            <%-- Technologies --%>
            <div class="secondCatHeader">
                Technologies
                <div class="secondaryMenuContainer" id="softwareDevTech">
                    <div class="secondaryMenu" style="COLOR: #3e3e3e" id="techMenu">
                        <div class="osmMenuObject">
                            .NET/ C#
                            <input type="hidden" value="ServicesHTML/SoftwareDevelopment/Applications/techCSharp.html" />
                            <div class="shortMenuDesc">
                                Our primary area of expertise, with over 5 years of experience.</div>
                        </div>
                        <div class="osmMenuObject">
                            MS-SQL
                            <input type="hidden" value="ServicesHTML/SoftwareDevelopment/Applications/techMsSQL.html" />
                            <div class="shortMenuDesc">
                                We have been working with SQL for over 6 years now.</div>
                        </div>
                        <div class="osmMenuObject">
                            MySQL
                            <input type="hidden" value="ServicesHTML/SoftwareDevelopment/Applications/techMySQL.html" />
                            <div class="shortMenuDesc">
                                Open Source Database for faster, hassle-free deployment.</div>
                        </div>
                        <div class="osmMenuObject">
                            Silverlight
                            <input type="hidden" value="ServicesHTML/SoftwareDevelopment/Applications/techSilverlight.html" />
                            <div class="shortMenuDesc">
                                Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque sit.</div>
                        </div>
                        <div class="osmMenuObject">
                            MVC
                            <input type="hidden" value="ServicesHTML/SoftwareDevelopment/Applications/techMVC.html" />
                            <div class="shortMenuDesc">
                                Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque sit.</div>
                        </div>
                        <div class="osmMenuObject">
                            Azure
                            <input type="hidden" value="ServicesHTML/SoftwareDevelopment/Applications/techAzure.html" />
                            <div class="shortMenuDesc">
                                Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque sit.</div>
                        </div>
                    </div>
                </div>
            </div>
            <%-- Applications --%>
            <div class="secondCatHeader">
                Applications
                <div class="secondaryMenuContainer" id="softwareDevApp">
                    <div class="secondaryMenu">
                        <div id="appMsCRM" class="osmMenuObject">
                            Microsoft CRM
                            <input type="hidden" value="ServicesHTML/SoftwareDevelopment/Technologies/appMsCRM.html" />
                            <div class="shortMenuDesc">
                                Our primary area of expertise, with over 5 years of experience.</div>
                        </div>
                        <div id="appQb" class="osmMenuObject">
                            QuickBooks
                            <input type="hidden" value="ServicesHTML/SoftwareDevelopment/Technologies/appQb.html" />
                            <div class="shortMenuDesc">
                                Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque sit.</div>
                        </div>
                        <div id="appGP" class="osmMenuObject">
                            Great Plains
                            <input type="hidden" value="ServicesHTML/SoftwareDevelopment/Technologies/appGp.html" />
                            <div class="shortMenuDesc">
                                Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque sit.</div>
                        </div>
                        <div id="appSP" class="osmMenuObject">
                            Sharepoint
                            <input type="hidden" value="ServicesHTML/SoftwareDevelopment/Technologies/appSp.html" />
                            <div class="shortMenuDesc">
                                Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque sit.</div>
                        </div>
                        <div id="appXero" class="osmMenuObject">
                            Xero
                            <input type="hidden" value="ServicesHTML/SoftwareDevelopment/Technologies/appXero.html" />
                            <div class="shortMenuDesc">
                                Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque sit.</div>
                        </div>
                        <div id="appFB" class="osmMenuObject">
                            Freshbooks
                            <input type="hidden" value="ServicesHTML/SoftwareDevelopment/Technologies/appFb.html" />
                            <div class="shortMenuDesc">
                                Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque sit.</div>
                        </div>
                        <div id="appSF" class="osmMenuObject">
                            SalesForce
                            <input type="hidden" value="ServicesHTML/SoftwareDevelopment/Technologies/appSF.html" />
                            <div class="shortMenuDesc">
                                Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque sit.</div>
                        </div>
                        <div id="appNav" class="osmMenuObject">
                            Navision
                            <input type="hidden" value="ServicesHTML/SoftwareDevelopment/Technologies/appNavision.html" />
                            <div class="shortMenuDesc">
                                Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque sit.</div>
                        </div>
                    </div>
                </div>
            </div>
            <%-- Independent Software Testing --%>
            <div class="mainCatHeaderWithoutChild">
                Independent Software Testing
                <input type="hidden" value="ServicesHTML/Testing.html" />
            </div>
            <%-- Technnical Documentation --%>
            <div class="mainCatHeaderWithoutChild">
                Technnical Documentation
                <input type="hidden" value="ServicesHTML/Documentation.html" />
            </div>
            <%-- Case Studies --%>
            <div class="mainCatHeaderWithChild">
                Case Studies
                <div class="secondaryMenuContainer">
                    <div class="secondaryMenu" style="COLOR: #3e3e3e">
                        <div class="osmMenuObject">
                            Media - Astral
                            <input type="hidden" value="ServicesHTML/CaseStudies/csAstral.html" />
                            <div class="shortMenuDesc">
                                Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque sit.</div>
                        </div>
                        <div class="osmMenuObject">
                            Waste Disposal - RGMRM
                            <input type="hidden" value="ServicesHTML/CaseStudies/csRGMRM.html" />
                            <div class="shortMenuDesc">
                                Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque sit.</div>
                        </div>
                        <div class="osmMenuObject">
                            Insurance - IAAH
                            <input type="hidden" value="ServicesHTML/CaseStudies/csIAAH.html" />
                            <div class="shortMenuDesc">
                                Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque sit.</div>
                        </div>
                        <div class="osmMenuObject">
                            Housing Providers - TalonPro
                            <input type="hidden" value="ServicesHTML/CaseStudies/csTalonPro.html" />
                            <div class="shortMenuDesc">
                                Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque sit.</div>
                        </div>
                        <div class="osmMenuObject">
                            Education and Training - Met Film
                            <input type="hidden" value="ServicesHTML/CaseStudies/csMetFilm.html" />
                            <div class="shortMenuDesc">
                                Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque sit.</div>
                        </div>
                        <div class="osmMenuObject">
                            Industry - Bates
                            <input type="hidden" value="ServicesHTML/CaseStudies/csBates.html" />
                            <div class="shortMenuDesc">
                                Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque sit.</div>
                        </div>
                        <div class="osmMenuObject">
                            Industry - Atdec
                            <input type="hidden" value="ServicesHTML/CaseStudies/csAtdec.html" />
                            <div class="shortMenuDesc">
                                Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque sit.</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

如果您需要任何其他代码或有任何其他疑问,请告诉我。

4

3 回答 3

3

这似乎是一种比赛条件。我不确定“为什么”部分,但这似乎解决了这个问题:

将您的 checkAndDisplay 函数替换为以下版本:

function checkAndDisplay(dialogToHide, divToShow) {
    $("#" + divToShow).css('display', 'block');
    setTimeout(function(){
        $("#" + dialogToHide).dialog("close");
    },500);
}

编辑:似乎 Internet Explorer 存在一个错误,除了鼠标移动外,没有刷新“悬停”状态。这是一个可重现的样本。尝试在不同的浏览器中单击绿色区域,不要移动鼠标。 http://jsfiddle.net/5LR8Z/

我没有找到针对该特定错误的任何解决方案。作为一种解决方法,我会尝试手动关闭菜单(在单击处理程序上设置一个变量,以了解在您的 checkAndDisplay 函数上要关闭哪个菜单)。

于 2013-06-12T20:34:35.543 回答
2

好的,因为没有适当的解决方法。这是我为规避问题所做的。有些人可能认为这有点骇人听闻,但我找不到任何其他解决方案。

如果您查看我的第三次更新,我将隐藏二级菜单,

        $(".osmMenuObject,.mainCatHeaderWithoutChild").click(function () {
            // Currently Selected
            $(".osmMenuObject,.mainCatHeaderWithoutChild").removeClass("osmServiceListSelected");
            $(this).addClass("osmServiceListSelected");
            // Hiding the div || THIS WAS NEW
            $(".secondaryMenuContainer").css('display', 'none');
            var pageToLoad = $(this).children("input[type='hidden']").val();
            loadPageInDiv("serviceLoadDivContainer", pageToLoad, "serviceLoadDiv", "osmPleaseWait");
            return false;
        });

现在,在document.ready()事件本身中,我正在添加另一个事件。

        $(".secondCatHeader,.mainCatHeaderWithChild").hover(function () {      
            $(this).children(".secondaryMenuContainer").css('display', '');
        })

现在这将做的是,每当我们将鼠标悬停在其中一个菜单项上,并且它有一个带有 class 的子项时.secondaryMenuContainer,它将清除该类的内联显示。所以display:none我之前设置的将被清除。我已经用 IE 9.0 和 Opera 对此进行了测试,它似乎工作正常。

感谢大家。

于 2013-06-17T04:45:23.940 回答
1

据我所知,您在第 1101 行和第 1109 行之间存在 CSS 冲突。您已设置.secondaryMenuContainerDISPLAY: none;但随后将其设置DISPLAY: block;.secondCatHeader:hover;

jQuery UI 对话框不会否定hover条件,因此您.secondaryMenuContainer永远不会恢复为DISPLAY: none;

$(".secondaryMenuContainer").css('display', '');不起作用,因为它设置了无效的内联样式,因此浏览器恢复为显示有效的外部样式,在这种情况下,DISPLAY: block;因为用户的样式hover仍然没有中断。如果你想.secondaryMenuContainer简单地级联回到它的DISPLAY: none;状态,你将不得不打破用户的悬停。

一种方法是在div加载对话框时创建一个空的;一个 z-index 高于你的.secondaryMenuContainer,占据整个窗口。div然后,当对话框淡出时,您将删除它。这应该打破用户的悬停并允许 div 的样式级联回DISPLAY: none;

编辑:因为这是 jQuery UI,所以模式框应该加载一个.ui-widget-overlay完全符合我描述的内容。该函数正在堆栈中被调用,e.widget._createOverlay @jquery-ui-1.10.1.custom.min.js:6但它并没有按照预期的方式停止页面交互。

于 2013-06-10T14:18:17.570 回答