如何在默认情况下关闭slideToggle?

时间:2013-10-26 11:42:58

标签: javascript jquery html menu slidetoggle

我正在创建一个带子菜单的菜单,该菜单用slideToggle打开子菜单。默认显示子菜单,请告诉我默认情况下它只显示菜单而不显示子菜单链接。

<span>Natural Rubber Reclaim</span>
  <ul>
  <div id="product_tabs">
     <li><a href='products.html'><span>Whole Tyre Reclaim</span></a></li>
     <li><a href='inner_tube_reclaim.html'><span>Inner Tube Reclaim</span></a></li>
  </div>
  </ul>


<span><a href='synthatic_reclaim_rubber.html'>Synthatic Reclaim Rubber</a></span>
<a href='products_5.html'><span>Crumb Rubber</span></a>

橡胶化合物

这是我正在使用的切换代码

<script>
        $(document).ready(function() {
            $('.accordion:eq(0)> span').click(function() {
                $(this).next().slideToggle('fast');
            });
        });
    </script>

1 个答案:

答案 0 :(得分:0)

尝试

$(document).ready(function () {
    $('.accordion:eq(0) > span').click(function () {
        $(this).next().slideToggle('fast');
    });
    $('.accordion:eq(0) > span').next().hide()
});

另一种解决方案是模拟点击事件

$(document).ready(function () {
    $('.accordion:eq(0) > span').click(function () {
        $(this).next().slideToggle('fast');
    }).click();
});