javascript - 嵌套 ul 显示在 anchor 单击上

标签 javascript jquery html

我的网站结构如下:

当我单击“add-info”时,ul 不显示,不太确定如何处理它以使其显示?

<ul>
    <li>Liebherr LHM 600 Mobile Harbour Crane. <a class="add-info" href="#">Find out more</a>
        <ul class="hidden-list">
            <li>Liebherr LHM 600 Mobile Harbour Crane. SWL of 208 Ton and capable of lifting 53.7 ton at 58 meters radius. Can be used for bulk container loading/unloading with our Bromma container handler attachment. Maximum hoisting height above quay of 59 metres.</li>
        </ul>
    </li>
    <li>Liebherr LR1300 Crawler Crane. <a class="add-info" href="#">Find out more</a>
        <ul class="hidden-list">
            <li>Coming December 2014 Liebherr LR1300 Crawler Crane. Can be configured to lift 300.5 ton and can be configured to a maximum radius of 80 metres. Can be fitted with a leader rig attachment and Bruce 16 ton piling hammer for piling.</li>
        </ul>
    </li>
    <li>Sennebogen 6130 Crawler Crane. <a class="add-info" href="#">Find out more</a>
        <ul class="hidden-list">
            <li>Sennebogen 6130 Crawler Crane. Can be configured to lift 136 ton and has a maximum radius of 42 metres.</li>
        </ul>
    </li>
    <li>Zoomlion RT55 Rough Terrain Crane. <a class="add-info" href="#">Find out more</a>
        <ul class="hidden-list">
            <li>RT55 Rough Terrain Crane. SWL of 54.88 ton and a maximum working radius radius of 41 metres. A main jib head height of 34 metres but also comes complete with a telescopic fly jib that can increase the head height up to a height of 54 metres and can be offset from 0 to 40 degrees.</li>
        </ul>
    </li>
    <li>Scheuerle 6 axel SPMT modular trailers complete with Z350 power pack units. <a class="add-info" href="#">Find out more</a>
        <ul class="hidden-list">
            <li>Scheuerle 6 axel SPMT modular trailers complete with Z350 power pack units. With a SWL of 48 ton per axel can be supplied in a vast array of different configurations.</li>
        </ul>
    </li>
    <li>Forklifts <a class="add-info" href="#">Find out more</a>
        <ul class="hidden-list">
            <li>Various sizes of forklifts available from 2.5 ton up to 32 ton.</li>
        </ul>
    </li>
</ul>

我想做的是在 jQuery 中单击“add-info”,显示 ul.hidden-list、SlideDown 或任何效果,只要它显示即可。

我创建了一个jsFiddle

我当前的 jQuery 代码:

$('.add-info').click(function() {

    $(this).children('ul.hidden-list').slideToggle();

    return false;
});

最佳答案

根据您的标记<ul>元素被放置为 <a> 的下一个元素而不是作为直系后代,所以 .next() (或 .siblings )方法应该使用:

$('.add-info').click(function() {
    $(this).next('ul.hidden-list').slideToggle();

    return false;
});

演示: http://jsfiddle.net/vog8bsLc/1/

关于javascript - 嵌套 ul 显示在 anchor 单击上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27543553/

相关文章:

jquery - 无法拖动对象的克隆 (JQuery)

javascript - ie9 上此 css3 动画的 jQuery 回退

javascript - 用另一个对象替换数组中的对象,ReactJS

javascript - 是否可以显示隐藏的输入值?

php - Jquery Datatables父子数据

javascript - 如何将sinon js注入(inject)到iFrame中的应用程序

html - css 弹出窗口影响 html 布局

javascript - 如果访问 anchor 标记,则设置其父元素的样式

javascript - 如何将以 0 开头的数字转换为与该值等效的字符串?

javascript - 在 JavaScript 中单击按钮后删除输出