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>
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.