Home > Web Front-end > JS Tutorial > jQuery implements the method of controlling the overflow of text content expressed by ellipses (…)_jquery

jQuery implements the method of controlling the overflow of text content expressed by ellipses (…)_jquery

WBOY
Release: 2016-05-16 15:13:18
Original
1497 people have browsed it

The example in this article describes the method of using jQuery to control the overflow of text content expressed by ellipses (…). Share it with everyone for your reference, the details are as follows:

How to limit the number of characters in jQuery

$(function(){
 //限制字符个数
$(".text").each(function(){
var maxwidth=23;
if($(this).text().length>maxwidth){ $(this).text($(this).text().substring(0,maxwidth)); $(this).html($(this).html()+'…');
}
});
});
<div class="text" style="width:150px;">你个杀千刀的,怎么写了这么多的文字,我要被拦腰截断了啊,天啊!</div>
<div class="text" style="width:150px;">你个杀千刀的,怎么写了这么多的文字,我要被拦腰截断了啊,天啊!</div>

Copy after login

Readers who are interested in more jQuery-related content can check out the special topics on this site: "JQuery drag effects and skills summary", "jQuery extension skills summary", "JQuery common classic special effects summary", "jQuery animation and special effects usage summary", "jquery selector usage summary" and "jQuery common plug-ins and usage Summary

I hope this article will be helpful to everyone in jQuery programming.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template