jQuery Toggle下拉菜单

时间:2012-03-18 19:45:37

标签: jquery html css

如何编写jQuery的一部分,以便在单击 Trials 时显示下拉菜单选项:

更新

jQuery(document).ready(function () {

    $("a[href='http://sheep.local/cms/trials']").click(function(e){
        e.preventDefault(); // In case you don't want the link to open...
        $(this).next('ul').slideToggle();
    });
});​

HTML:

       <div id="mainnavwrap">
            <div id="mainnav" class="clearfix">
    <ul class="menu">
    <li class="first current">
        <a href="http://sheep.local/cms/home">Home</a>
    </li>
    <li>
        <a href="http://sheep.local/cms/features">Features</a>
    </li>
    <li>
        <a href="http://sheep.local/cms/options">Options</a>
    </li>
    <li>
        <a href="http://sheep.local/cms/pumps-motors">Pumps & Motors</a>
    </li>
    <li>
        <a href="http://sheep.local/cms/shows">Shows</a>
    </li>
    <li>
        <a href="http://sheep.local/cms/trials">Trials</a>
        <ul>
            <li class="first">
                <a href="http://sheep.local/cms/trials/mathews-trial">Mathews Trial</a>
            </li>
            <li>
                <a href="http://sheep.local/cms/trials/novatis-trial">Novatis Trial</a>
            </li>
            <li>
                <a href="http://sheep.local/cms/trials/waimati-vet-trial">Waimati Vet Trial</a>
            </li>
            <li class="last">
                <a href="http://sheep.local/cms/trials/uk-scab-mite-trial">UK Scab Mite Trial</a>
            </li>
        </ul>
    </li>
    <li class="last">
        <a href="http://sheep.local/cms/contact">Contact</a>
    </li>

    </ul>
</div>
          </div> 

CSS:

#wrapper #contentarea #blue_box .centerblue_txt ul li ul{
    width:190px;
    padding:5px 0 0 10px;
    display:none;
}
#wrapper #contentarea #blue_box .centerblue_txt ul li ul li{
    width:185px;
    padding:5px 0 5px 5px;
    border-top:1px dotted #424242;
    border-bottom:0px;
}
#wrapper #contentarea #blue_box .centerblue_txt ul li ul li a,
#wrapper #contentarea #blue_box .centerblue_txt ul li ul li a{
    width:180px;
    padding:0 0 0 10px;
    font-size:12px;
    background:url(../img/liBullets.gif) no-repeat left 4px;
}
#wrapper #contentarea #blue_box .centerblue_txt ul li ul li#current a,
#wrapper #contentarea #blue_box .centerblue_txt ul li ul li a:hover{
    color:#D1D1D1;
    background:url(../img/liBullets.gif) no-repeat left 4px;
}
#wrapper #contentarea #blue_box .centerblue_txt ul li a:hover, 
#wrapper #contentarea #blue_box .centerblue_txt ul li a:active {
    background:#5490f3;
}

2 个答案:

答案 0 :(得分:1)

看一下这段代码:http://jsfiddle.net/G9kda/6/ 点击“deelnemers”以获得所需的效果。

编辑:我把它调整为您的代码: http://jsfiddle.net/hXNnD/1/

答案 1 :(得分:0)

你可以使用这样的东西(仅用于试验)

$("a[href='http://sheep.local/cms/trials']").click(function(e){
    e.preventDefault(); // In case you don't want the link to open...
    $(this).nextAll('ul').slideToggle();
});