单击下拉菜单不起作用,所有菜单下拉



我正在为我的网站处理点击脚本的下拉列表,但它并没有完全按照我想要的方式工作。(http://blazebass.com/version2/?pagina=blazers)

当我单击按钮 1 时,按钮 2 也会下拉。我不要这个。

页面代码如下:

<TABLE BORDER="0" align="center">
<TR><TD>    
<div class="click-nav">
<ul class="no-js">
<li>
<div class="button_blazer"><a class="clicker"><font color="white">VANCED (Producer / DJ)                </font></a></div>
<ul>
<li class="button_content">
<div class="soundcloud"><center><b><a href="http://www.soundcloud.com/vanced"         target="_new">SOUNDCLOUD</a></b></center></div>
<div class="facebook"><center><b><a href="https://www.facebook.com/vanceddubstep"     target="_new">FACEBOOK</a></center></div>
<br><br>
<u>UPCOMING EVENTS:</u><br>
<a href="https://www.facebook.com/events/1411434522422784" target="_new"><img     width="15px" height="15px" src="images/facebook_button_small.png" border="0"></a>
&nbsp;18/04/2014 - BLAZEBASS 2<br>
<a href="https://www.facebook.com/events/708468632520791" target="_new"><img width="15px"     height="15px" src="images/facebook_button_small.png" border="0"></a>
&nbsp;25/04/2014 - DUBSTEP RIDDIM SESSION/PLAN B (Moscow)<br> 
<a href="https://www.facebook.com/events/282338108583569" target="_new"><img     width="15px" height="15px" src="images/facebook_button_small.png" border="0"></a>
&nbsp;09/05/2014 - 30.000 WATTS<br>
<a href="https://www.facebook.com/events/286445134839854" target="_new"><img width="15px" height="15px" src="images/facebook_button_small.png" border="0"></a>
&nbsp;23/05/2014 - DUBNIUM<br>
<br>
<u>PAST EVENTS:</u><br>
<a href="https://www.facebook.com/pages/Dubconscious/124580511077196?fref=ts" target="_new"><img width="15px" height="15px" src="images/facebook_button_small.png"         border="0"></a>
&nbsp;20/12/2013 - DUBCONSCIOUS 3<br>
<a href="https://www.facebook.com/blazebass" target="_new"><img width="15px" height="15px" src="images/facebook_button_small.png" border="0"></a>
&nbsp;18/04/2013 - BLAZEBASS 1<br>
</li></ul></li></ul>
</div>
</TD><TD>
<div class="click-nav" STYLE="margin-left: 10px;">
<ul class="no-js">
<li>
<div class="button_blazer"><a class="clicker"><font color="white">VANCED (Producer / DJ)            </font></a></div>
<ul>
<li class="button_content">
<div class="soundcloud"><center><b><a href="http://www.soundcloud.com/vanced"     target="_new">SOUNDCLOUD</a></b></center></div>
<div class="facebook"><center><b><a href="https://www.facebook.com/vanceddubstep"             target="_new">FACEBOOK</a></center></div>
<br><br>
<u>UPCOMING EVENTS:</u><br>
<a href="https://www.facebook.com/events/1411434522422784" target="_new"><img     width="15px" height="15px" src="images/facebook_button_small.png" border="0"></a>
&nbsp;18/04/2014 - BLAZEBASS 2<br>
<a href="https://www.facebook.com/events/708468632520791" target="_new"><img     width="15px" height="15px" src="images/facebook_button_small.png" border="0"></a>
&nbsp;25/04/2014 - DUBSTEP RIDDIM SESSION/PLAN B (Moscow)<br> 
<a href="https://www.facebook.com/events/282338108583569" target="_new"><img     width="15px" height="15px" src="images/facebook_button_small.png" border="0"></a>
&nbsp;09/05/2014 - 30.000 WATTS<br>
<a href="https://www.facebook.com/events/286445134839854" target="_new"><img width="15px" height="15px" src="images/facebook_button_small.png" border="0"></a>
&nbsp;23/05/2014 - DUBNIUM<br>
<br>
<u>PAST EVENTS:</u><br>
<a href="https://www.facebook.com/pages/Dubconscious/124580511077196?fref=ts"         target="_new"><img width="15px" height="15px" src="images/facebook_button_small.png"         border="0"></a>
&nbsp;20/12/2013 - DUBCONSCIOUS 3<br>
<a href="https://www.facebook.com/blazebass" target="_new"><img width="15px"     height="15px" src="images/facebook_button_small.png" border="0"></a>
&nbsp;18/04/2013 - BLAZEBASS 1<br>
</li></ul></li></ul>
</div>
</TD></TR>
</TABLE>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$(function() {
    // Clickable Dropdown
    $('.click-nav > ul').toggleClass('no-js js');
    $('.click-nav .js ul').hide();
    $('.click-nav .js').click(function(e) {
        $('.click-nav .js ul').slideToggle(200);
        $('.clicker').toggleClass('active');
        e.stopPropagation();
    });
    $(document).click(function() {
        if ($('.click-nav .js ul').is(':visible')) {
            $('.click-nav .js ul', this).slideUp();
            $('.clicker').removeClass('active');
        }
    });
});
</script>

您可以通过e.currentTarget访问单击的元素,因此您基本上可以将侦听器更改为如下所示的内容:

$('.click-nav .js').click(function(e) {
    $('ul', e.currentTarget).slideToggle(200);
    $('.clicker', e.currentTarget).toggleClass('active');
    e.stopPropagation();
});

这样做是将"ul"和".clicker"之后的搜索限制在实际单击的区域。

此外,作为提示,您应该在代码中使用缩进,因为它很难阅读。

最新更新