How to hide/show more text within a certain length (like youtube)

前端 未结 14 756
说谎
说谎 2020-11-28 21:24

I want to have a text to only be a certain amount of characters/length and after that length, I want to put a link to reveal the full length of the text.

The link w

14条回答
  •  北荒
    北荒 (楼主)
    2020-11-28 22:18

    You can use like this

    $(".jsgrid-cell").each(function(i,v){
        var txt=$(v).text();
        if(txt.length>100){
            var shortText=txt.substring(0, 100)+
            ""+
                "..."+
            ""+
            ""+
                txt.substring(100, txt.length)+
            "";
    
            $(v).html(shortText );
        }
    });
    

提交回复
热议问题