本文介绍了jquery限制段落中的行并将三个句点应用到结尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿大家,我一直在寻找这个解决方案,但只找到了限制字符的解决方案。我有以下代码:

Hey everyone, I've been looking around for this solution but have only found solutions regarding limiting characters. I have the following code:

<div id = "ta_0" style="display: none;">
   <a href = "news.html">IRS announces 2011 COLA limits for qualified retirement plans</a>
   <br />Most retirement plan contribution and benefit limits for 2011 will
be unchanged from 2010, the IRS has announced. The 2011 cost of
living adjustments (COLAs), as applied by their Internal Revenue
C...</div>

我想将锚文本后的文字后面的字符数限制为两行。我知道我可以限制字符限制,但这可能会减少一半的字数。相反,我只是想让他们停下来。我还想在限制结束时追加......。

I would like to limit the amount of characters after in the text after the anchor text to two lines. I know that I can limit the character limit but that might cut words in half. Instead I just want them to stop. I'd also like to append "..." at the end of the limit.

有任何建议吗?

推荐答案

为了做到这一点,你需要计算每一行的文本宽度,特别是如果你使用比例宽度字体。

In order to do that, you would need to calculate the text width of each line, particularly if you are using a proportional width font.

我建议你看一下这个问题:

I would suggest having a look at this question: Calculate text width with JavaScript

这个问题处理如何执行文本度量操作的问题。我会在构造中使用它,一次向一个句子添加一个单词,当超过限制时,开始一个新行并在达到足够的行时停止。

That questions deals with the question of how to perform text metric operations. I would use that in construction with adding one word at a time to a sentence, and when over the limit, starting a new line and stopping when enough lines were achieved.

这篇关于jquery限制段落中的行并将三个句点应用到结尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 00:33