两个菜单的点击事件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了两个菜单的点击事件相关的知识,希望对你有一定的参考价值。

监听的事件具体,这样不会联动

<ul>
<li class="two">
<a><h3>啦啦啦</h3></a>
<ul class="three">
<li class="five">啦啦啦</li>
<li class="five">啦啦啦</li>
<li class="five">啦啦啦</li>
</ul>
</li>
<li class="two">
<a><h3>哦哦哦</h3></a>
<ul class="three">
<li class="five">啦啦啦</li>
<li class="five">啦啦啦</li>
<li class="five">啦啦啦</li>
</ul>
</li>
</ul>

 

<style>
li {
list-style: none;
}
.active {
color: blue;
}
.activee {
color: red;
}
.three {
display: none;
}
</style>

主要代码内容

<script>
$(‘.two>a‘).click(function () {
$(this).parent().addClass(‘active‘).siblings().removeClass(‘active‘);

var three = $(this).parent().find(‘ul‘);
if (three.css(‘display‘) == ‘none‘) {
three.show();
}else {
three.hide();
}
});

$(‘.five‘).click(function (){
$(this).addClass(‘activee‘).siblings().removeClass(‘activee‘);
})
</script>

 

以上是关于两个菜单的点击事件的主要内容,如果未能解决你的问题,请参考以下文章