gpt4 book ai didi

javascript - 想要隐藏正文点击的子菜单

转载 作者:行者123 更新时间:2023-11-29 22:12:58 25 4
gpt4 key购买 nike

我想在正文点击时隐藏我的子菜单。目前它不是这样工作的,它只在点击下拉菜单项时隐藏。这是菜单所在的 ( https://deva.yuave.com) 站点。我试图在 body 点击时隐藏它,但它不会工作。请帮助..这是我用于子菜单的javascript代码..

<script type="text/javascript">
<!--

window.onload=function() {
subMenusO = getElementsByClassName(document,'ul','subMenus');
}
//-----------------------------------------------------------

function showSubMenu(elemId) {
var dispStatus = (document.getElementById(elemId).style.display == 'block')? 'none' : 'block';
//hide any visible submenus
for(var i=0; i < subMenusO.length; i=i+1) {
subMenusO[i].style.display = 'none';
}
//show/hide this menu id
document.getElementById(elemId).style.display = dispStatus;
}
//--------------------------------------------------------------------------

function getElementsByClassName(oElm, strTagName, strClassName){
var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
var arrReturnElements = new Array();
strClassName = strClassName.replace(/\-/g, "\\-");
var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
var oElement;
for(var i=0; i<arrElements.length; i++)
{
oElement = arrElements[i];
if(oRegExp.test(oElement.className))
{
arrReturnElements.push(oElement);
}
}
return (arrReturnElements)
}

//-->
</script>

最佳答案

像这样

$(document).click(function(e) {
if (!$(e.target).is(".subMenus")){
// hide submenus
$('.subMenus').hide();
}
});

关于javascript - 想要隐藏正文点击的子菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17043253/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com