Jump to content
  • 0

Вопросс


woofs
 Share

Question

Здравствуйте,

у меня есть саб меню которое при щелчке расскрывается, можноли сделать так, чтобы при щелчке например по второму меню, первое открытое закрывалось, т.е. чтобы не было таково чтобы все саб меню были раскрыты, а только одно из.

<script type="text/javascript">
function allClose(){
var list = document.getElementById("menu").getElementsByTagName("ul");
for(var i=0;i<list.length;i++){
list[i].style.display = "none";
}
}
function openMenu(node){
var subMenu = node.parentNode.getElementsByTagName("ul")[0];
subMenu.style.display == "none" ? subMenu.style.display = "block" : subMenu.style.display = "none";
}
</script>

<ul id="menu"><li><a href="#" onclick="openMenu(this);return false">Меню 1</a>
<ul>
<li><a href="#">sub menu 1</a></li>
<li><a href="#">sub menu 2</a></li>
<li><a href="#">sub menu 3</a></li>
<li><a href="#">sub menu 4</a></li>
<li><a href="#">sub menu 5</a></li>
<li><a href="#">sub menu 6</a></li>
<li><a href="#">sub menu 7</a></li>
</ul></li>
<li ><a href="#" onclick="openMenu(this);return false">Menu 2</a>
<ul><li><a href="#">sub menu 1</a></li>
<li><a href="#">sub menu 2</a></li>
<li><a href="#">sub menu 3</a></li>
<li><a href="#">sub menu 4</a></li>
<li><a href="#">sub menu 5</a></li>
<li><a href="#">sub menu 6</a></li>
<li><a href="#">sub menu 7</a></li>
</ul></li></ul>

#menu{width:100%;list-style-type:none;padding-left:0px;margin:0; border-top:1px solid #b3b3b3; }
#menu ul li { list-style-type:disc;margin:0; padding:2px;}
#menu ul{ padding-left: 25px; background: #fbfbfb; border-bottom:1px solid #b3b3b3;margin:0;}
#menu li ul li a{ padding:2px; color:#000066; background: #fbfbfb; border:0;margin:0; display: block; text-align:left;display:compact ; font-weight: normal;}
#menu li ul li a:hover{ padding-left:4px; color: red;background: #fbfbfb;margin:0;display: compact; font-weight: bold; }
#menu li a{color:#000; padding:7px; background:#E7DFCA; border-bottom:1px solid #b3b3b3;margin:0;display:block; font-weight:bold;}
#menu li a:hover{color: #999999; display:block;}
#menu li { text-align:center;}

Edited by woofs
Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0
<script type="text/javascript">
function allClose(){
var list = document.getElementById("menu").getElementsByTagName("ul");
for(var i=0;i<list.length;i++){
list[i].style.display = "none";
}
}
function openMenu(node){
//закроем все саб меню
allClose()
//открываем нужное
var subMenu = node.parentNode.getElementsByTagName("ul")[0];
subMenu.style.display == "none" ? subMenu.style.display = "block" : subMenu.style.display = "none";
}
</script>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy