通过ajax显示评论的全文或短文本

show full or short text of review via ajax

本文关键字:文本 ajax 显示 评论 通过      更新时间:2023-09-26

我在页面上有一个块,它显示了对审查的简短描述
参见jsfiddle 上的布局

我想意识到,当用户点击链接(在div内用类nickname标记a)时,会显示完整的评论,反之亦然。

最好的方法是什么?

我认为应该采取以下方式:例如,当用户点击链接时,发送ajax请求进行全面审查,如果现在显示全面审查,则再次发送请求,但仅获得300个字符。但是,对于这种方式,我需要发送两个请求。

利用您的代码:http://jsfiddle.net/sessa/mv87M/20/

请确保通过CSS隐藏span.more-text。这里使用拨动开关非常完美。

$('.nickname').click(function() {
       $(this).next('.text').find('.more-text').toggle();
       $(this).next('.text').find('.ellipses').toggle();
});
$("p").click(function(){
    if($(".new",this).is(":visible"))
    $(".new",this).hide();
    else
            $(".new",this).show();
});

这是演示http://jsfiddle.net/mv87M/17/show/

This is my small blurb of text.....
...................................
...................................

<div id="hiddentext" style="display:none;">
Hidden more text...................
...................................
...................................
</div>

显示全文

Javascript(使用jquery):

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