条带格式的文本

时间:2018-11-02 15:42:43

标签: javascript html

我有一个嵌套的html,我想限制其内容。

有什么办法吗?

有一个例子:

<div id="description-list-31553" style="display: flow-root;">
    <p dir="ltr" style=""><span id="docs">
    	<span ">Many people regularly put</span>
        <a href="https://www.realbuzz.com/challenges/run-a-marathon/">running a marathon</a>
        <span style="color: rgb(51, 51, 51);">&nbsp;in their list of things to do before they die, so why not make this the year that you actually do it? </span></span></p>
    <p dir="ltr"><span><span ></span><span style="color: rgb(173, 0, 87);">Completing a marathon is a great personal achievement that requires months of dedication to training, and the exhilaration you’ll feel when crossing the line will certainly be something special</span><span style="color: rgb(51, 51, 51);">. </span></span></p>
    <p dir="ltr"><span><span style="color: rgb(51, 51, 51);">If you’re already a marathon runner, then why not consider taking on some of the more extreme running events such as the Great Wall Marathon in China, the Antarctica Marathon, or even the Marathon des Sables run in the Sahara Desert?</span></span><span style="color: rgb(51, 51, 51);">&nbsp;&nbsp;</span></p><h2 dir="ltr" ></h2>
</div>

我只需要保留其格式的一部分内容即可。

<div id="description-list-31553" style="display: flow-root;">
    <p dir="ltr" style=""><span id="docs">
    	<span ">Many people regularly put</span>
        <a href="https://www.realbuzz.com/challenges/run-a-marathon/">running a marathon</a>
        <span style="color: rgb(51, 51, 51);">&nbsp;in their list of things to do before they die, so why not make this the year that you actually do it? </span></span></p>
    <p dir="ltr"><span><span ></span><span style="color: rgb(173, 0, 87);">Completing a marathon ...</span><span style="color: rgb(51, 51, 51);">. </span></span></p>
    <p dir="ltr"><span><span style="color: rgb(51, 51, 51);"></span></span><span style="color: rgb(51, 51, 51);">&nbsp;&nbsp;</span></p><h2 dir="ltr" ></h2>
</div>

1 个答案:

答案 0 :(得分:0)

如果您使用的是jQuery,则可以尝试以下插件: http://dotdotdot.frebsite.nl/

编辑

也许这篇文章可以为您提供帮助,您必须用n个给定字符的子字符串替换文本,并在末尾添加三个点

Truncate text to fit in 3 lines and show three dots in end In Html