javascript - 切换效果 了解更多

标签 javascript jquery

<div class="post-content">
        <p>Random text >Random text >Random text Random text >Random text >Random text Random text >Random text >Random text Random text >Random text >Random text Random text >Random text >Random text Random text >Random text >Random text Random text >Random text >Random text Random text >Random text >Random text Random text >Random text >Random text Random text >Random text >Random text Random text >Random text >Random text Random text >Random text >Random text </p>
        <p>More text More text More text More text More text More text More text More text More text More text More text More text More text More text More text More text More text More text More text More text More text More text More text More text </p> 
        <span class="more">more/less</span>
</div>
<小时/>
$('.post-content p:not(:first-child)').css('display', 'none');

$(".more").click(function () {
    $('.post-content p:not(:first-child)').css('display', 'block');
});

demo

问题很明显。我需要制作一个 Toogle 效果来显示隐藏第一段之后的所有 p

最佳答案

使用隐藏切换代替:

// cache elements so you don't repeatedly query the DOM
toggleParas = $('.post-content p:not(:first-child)');

toggleParas.hide();

$(".more").click(function () {
    toggleParas.toggle();
});

关于javascript - 切换效果 了解更多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20389490/

相关文章:

javascript - 突出显示具有不同值的表列 td

javascript - 固定图像从 3D 转换中消失?

javascript - html限制跨度中的字母

javascript - TypeScript 中封装的工作原理

javascript - 如何在 marrionete.js 中构建调用链渲染 itemView,并使用 itemView 内的异步函数进行延迟

javascript - 如果使用多个导入而不是一个命名导入,是否会有性能成本

javascript - 尝试单击时菜单不会保持打开状态

javascript - react 条件渲染与状态

javascript - 两种方法互相替换(window.onload/Canvas JS)?

jQuery UI,如何获取放置元素的元素id?