2014-05-02 54 views
0

我有这个代码具有文本功能显示/隐藏,现在“显示文本”和“隐藏文本”都是可见的,任何人都有任何想法,我可以如何让链接显示和隐藏太?显示/隐藏文本JQuery

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

    }); 

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

你是什么意思的链接显示和隐藏?也许在你的问题中添加一些HTML,以更详细地解释你正在尝试做什么 – krilovich

+0

你是否也可以分享你的html ... – pbenard

+1

添加你的html代码 – Leo

回答

0

试试这个

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

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

这也应该适用

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

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

感谢那些工作:) – user3426597

0

而不是使用2个按钮,你为什么不只能使用一个,跟.toggle(),这样,你不不必隐藏和显示按钮。

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

这是一个link如果你想查看它的文档。此外,如果你想给更多花哨的效果,你可以尝试.slideToggle().fadeToggle(),我个人喜欢更多的淡入淡出。