显示/隐藏文本JQuery

时间:2014-05-02 17:35:59

标签: javascript jquery

我有这个代码,它具有显示/隐藏文本的功能,现在"显示文本"和"隐藏文字"两者都是可见的,任何人都有任何想法,我怎么能有链接显示和隐藏呢?

$(document).ready(function(){
  $("#hide").click(function(){
    $(".content_post").hide();

  });

  $("#show").click(function(){
    $(".content_post").show();
  });
});

3 个答案:

答案 0 :(得分:1)

这也应该有效

$(document).ready(function(){
    $("#hide").click(function(){
       $(".content_post").hide();
       $(this).hide();
       $("#show").show();

    });
    $("#show").click(function(){
        $(".content_post").show();
        $(this).hide();
        $("#hide").show();
    });
});

答案 1 :(得分:0)

试试这个

$(document).ready(function(){
  $("#hide").click(function(){
    $(".content_post").hide();
    $("#hide").hide();
    $("#show").show();
  });

  $("#show").click(function(){
    $(".content_post").show();
    $("#hide").show();
    $("#show").hide();
  });
});

答案 2 :(得分:0)

为什么不使用.toggle(),而不是使用2个按钮,这样您就不必隐藏和显示按钮。

$('#button').click(function(){
    $('.content_post').toggle();
});

如果要查看文档,请参阅以下文档link。此外,如果你想给出一个更有花哨的效果,你可以试试.slideToggle().fadeToggle(),我个人更喜欢褪色。