2

http://jsfiddle.net/xfPxp/

基本的に、多層スライドダウンクリックメニューを作成しようとして、サブメニューをslideDownにしましたが、子をクリックしたときに親がslideUp-ingを停止する方法がわかりません。助けてくれてありがとう!

HTML コード ------------------------------------------------ ------------------------

<!--Nav Menu 1-->

<ul class="make">Club Car
    <ul class="model" style="display: none">Precedent
        <ul class="product" style="display: none">Brush Guard</ul>
        <ul class="product" style="display: none">Lift Kits</ul>
    </ul>

    <ul class="model" style="display: none">DS
        <ul class="product" style="display: none">Brush Guard</ul>
        <ul class="product" style="display: none">Lift Kits</ul>
    </ul>
</ul>

<!--- Nav Menu 2-->

<ul class="make">E-Z-Go
    <ul class="model" style="display: none">TXT
        <ul class="product" style="display:none">Brush Guard</ul>
        <ul class="product" style="display:none">Lift Kits</ul>
    </ul>

    <ul class="model" style="display: none">RXV
        <ul class="product" style="display:none">Brush Guard</ul>
        <ul class="product" style="display:none">Lift Kits</ul>
    </ul>

Jquery スクリプト ------------------------------------------------ --

<script>
$("ul.make").click(function () {
        if ($(this).children('ul').is(":hidden")) {
            $(this).children('ul').slideDown("fast");
        }
        else {
            $(this).children('ul').slideUp("fast");
        }
});
$("ul.model").click(function () {
    if ($(this).children('ul').is(":hidden")) {
        $(this).children('ul').slideDown("fast");
    }
    else {
        $(this).children('ul').slideUp("fast");
    }
});
</script>
4

2 に答える 2

3

.stopPropagation関数に渡すonを使用しeventます。

$("ul.make").click(function (event) {
    event.stopPropagation();
    if ($(this).children('ul').is(":hidden")) {
        $(this).children('ul').slideDown("fast");
    } else {
        $(this).children('ul').slideUp("fast");
    }
});

$("ul.model").click(function (event) {
    event.stopPropagation();
    if ($(this).children('ul').is(":hidden")) {
        $(this).children('ul').slideDown("fast");
    } else {
        $(this).children('ul').slideUp("fast");
    }
});

デモ: http://jsfiddle.net/xfPxp/1/

于 2013-07-08T14:31:38.400 に答える