Home  >  Article  >  Web Front-end  >  How to implement excess ellipses in jquery

How to implement excess ellipses in jquery

藏色散人
藏色散人Original
2021-11-19 11:19:021993browse

Jquery method to implement excess ellipses: 1. Create a js sample file; 2. Use the "$(".ftlt_lt_wzne").each(function() {...}" method to achieve the merging of limited text Just use an ellipsis when exceeding.

How to implement excess ellipses in jquery

The operating environment of this tutorial: windows7 system, jquery3.2.1 version, Dell G3 computer.

How does jquery realize the ellipsis that exceeds the limit?

jquery uses ellipses to limit the text beyond the limit

We all know that using css3 can display ellipses beyond one line, but using css3 for multiple lines is very troublesome. We also need to consider compatibility. Today we use jquery to determine the number of words to limit the occurrence of ellipses

$(".ftlt_lt_wzne").each(function() {
var maxwidth =36;//显示多少字符
if ($(this).text().length > maxwidth) {
$(this).text($(this).text().substring(0, maxwidth));
$(this).html($(this).html() + '...');
}
});

Recommended study: "jquery video tutorial"

The above is the detailed content of How to implement excess ellipses in jquery. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn