截断文本以适合 3 行并在 Html 中显示三个点 [英] Truncate text to fit in 3 lines and show three dots in end In Html

查看:17
本文介绍了截断文本以适合 3 行并在 Html 中显示三个点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将文本显示为段落,但只显示三行并截断测试,同时在段落末尾添加...(三个点).

I need to display a text as paragraph, but display only three lines and truncate the test while adding ...(three dots) in the paragraph end.

推荐答案

计算可以容纳 3 行的字符串的最大长度并使用以下脚本

Calculate max length of string which can fit into 3 lines and use the following script

var maxLength = 140;
var result = yourString.substring(0, maxLength) + '...';

这篇关于截断文本以适合 3 行并在 Html 中显示三个点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆