【发布时间】:2016-01-13 00:03:56
【问题描述】:
(我的java脚本是基础的,正在学习中) 我正在尝试使用我在此处找到的脚本中的一些复制粘贴来制作菜单导航,但结果并不像我想要的那样完美。
这就是重点,我想要:
点击一个--div--
- 从它的 -ul- 中显示 -li-
- 其他 –div– 隐藏
- 单击 -li- 链接不会显示其他 -div-,它们保持隐藏状态
点击返回相同的-div-
全部-li-隐藏
显示所有其他 –div– 和 –ul–(不是 –li–)
希望问题清楚,感谢任何评论。
谢谢!
$(document).ready(function () {
$("ul").click(function (evt) {
if(evt.target.tagName != 'UL')
return;
$("li", this).toggle();
});
});
$(".SHOW").click(function(){
$(this).siblings("div").toggle();
});
ul li{list-style: none;}
a {text-decoration: none;}
ul a {color: black;}
li a {color: #493A3A;; }
.GER, .ARG, .SPAIN {
position: absolute;
width: 200px;
text-align: center;
border: solid 2px gray;
margin: 0;
padding: 0;
font-size: 30px;
line-heigth: 40px;
}
.ARG {left: 220px; top: 8px}
.SPAIN {left: 431px; top: 8px}
.GERLI, .ARGLI, .SPALI {font-size: 18px; height: 35px; line-height:36px; display:none}
.GERLI:nth-child(1) {background-color: yellow;}
.GERLI:nth-child(2) {background-color: Red;}
.GERLI:nth-child(3) {background-color: Black;}
.ARGLI:nth-child(1) {background-color: lightblue;}
.ARGLI:nth-child(2) {background-color: white;}
.ARGLI:nth-child(3) {background-color: lightblue;}
.SPALI:nth-child(1) {background-color: red;}
.SPALI:nth-child(2) {background-color: yellow;}
.SPALI:nth-child(3) {background-color: red;}
.GER:hover, .ARG:hover, .SPAIN:hover{background-color: lightgray;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="SHOW">
<ul class="GER">Germany
<li class="GERLI"><a href="http://blank.org/" target="_blank">Bratwurst</a></li>
<li class="GERLI"><a href="http://blank.org/"target="_blank">Chucrut</a></li>
<li class="GERLI"><a href="http://blank.org/"target="_blank">Ketchup</a></li>
</ul>
</div>
<div class="SHOW">
<ul class="ARG">Argentina
<li class="ARGLI"><a href="http://blank.org/"target="_blank">Churrasco</a></li>
<li class="ARGLI"><a href="http://blank.org/"target="_blank">Mate</a></li>
<li class="ARGLI"><a href="http://blank.org/" target="_blank">Pampa</a></li>
</ul>
</div>
<div class="SHOW">
<ul class="SPAIN">Spain
<li class="SPALI"><a href="http://blank.org/" target="_blank">Paella</a></li>
<li class="SPALI"><a href="http://blank.org/" target="_blank">Flamenco</a></li>
<li class="SPALI"><a href="http://blank.org/" target="_blank">Toros</a></li>
</ul>
</div>
jsfiddle:
【问题讨论】:
标签: javascript navigation