Show only first two rows from a paragraph

后端 未结 4 844
我在风中等你
我在风中等你 2021-01-15 15:09

I need to display some text on two lines, and add some \"...\" if the text is too long.

Example :

This is some long text and we need to show it on only two         


        
4条回答
  •  轮回少年
    2021-01-15 15:53

    You can do a slice and embed it along with the dots while rendering, and play around with the css width to make it two lined.

    .js file

    var text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor"
    

    .ejs file

    <%= text.slice(0,30)+" ..." %>

提交回复
热议问题