下拉单击无法正常工作,所有菜单都会下拉

时间:2014-03-04 10:13:16

标签: javascript jquery html dropdownbox

我正在为我的网站制作点击脚本的下拉列表,但它不能完全按照我的要求工作。 (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>

1 个答案:

答案 0 :(得分:0)

您可以通过e.currentTarget访问您点击的元素,这样您就可以将听众改为:

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

这样做会将'ul'和'.clicker'之后的搜索限制在实际点击区域。

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