JQuery切换多个Div +阅读更多/阅读更少

时间:2014-10-23 06:10:39

标签: jquery css image

全新的jQuery,因为我相信你很快就会知道。

我一直在浏览论坛,寻找我遇到过的两个主要问题的解决方案:

  • 多个div之间的独立切换&
  • 'Read More'&之间切换'显示更少'

下面是我用于该页面的脚本,但是当我选择一个特定的div,其中显示下面的其他内容时,显示图像被隐藏&替换为'显示更少'

$(".stage-description").slideUp();

$(".stage-logo").click(function(){
    $(".stage-description").not($(this).next()).hide(1);
    $(this).next(".stage-description").slideToggle("1");
    $(this).text( $(this).text() == 'Show Less' ? "Read More" : "Show Less");
});

以下是我遇到此问题的示例页面。

http://jsfiddle.net/raym01/qmg4bxra/

非常感谢任何帮助!

干杯

1 个答案:

答案 0 :(得分:0)

将第5行更改为:

$(this).children().last().text( 
    $(this).children().last().text() == 'Show Less' ? "Read More" : "Show Less"
);

要访问多个元素,您可以使用.each()并使用$(this)

示例:

$('.article-less-button').each(function (){
    $(this).click(function(){
        $(this).parent().toggle();
        or
        $(this).parent().children().last().toggle();//to toggle another element 
        ...
    })
})

http://api.jquery.com/jquery.each/

相关问题