Home > Web Front-end > JS Tutorial > body text

Introduction to using the jquery equal-width output text plug-in_jquery

WBOY
Release: 2016-05-16 17:22:19
Original
1045 people have browsed it
复制代码 代码如下:



<script> <br>(function($){ <br>$.extend($,{ <br>fixedWidth:function(str,length,char){ <br>str=str.toString(); <br>if(!char) char="..."; <br>var num=length-lengthB(str); <br>if(num<0){ <BR>str=substringB(str,length-lengthB(char)) char; <BR>} <BR>return str; <BR>function substringB(str,length){ <BR>var num=0,len=str.length,tenp=""; <BR>if(len){ <BR>for(var i=0;i<len;i ){ <BR>if(num>length) break; <br>if(str.charCodeAt(i)>255){ <br>num =2; <br>tenp =str.charAt(i); <br>}else{ <br>num ; <br>tenp =str.charAt(i); <br>} <br>} <br>return tenp; <br>}else{ <br>return null; <br>} <br>} <br>function lengthB(str){ <br>var num=0,len=str.length; <br>if(len){ <br>for(var i=0;i<len;i ){ <BR>if(str.charCodeAt(i)>255){ <br>num =2; <br>}else{ <br>num ; <br>} <br>} <br>return num; <br>}else{ <br>return 0; <br>} <br>} <br>} <br>}); <br>})(jQuery); <br>var a="abcde我是谁呢?"; <br>alert(jQuery.fixedWidth(a,10)); <br></script>
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