Home > Web Front-end > JS Tutorial > js, intercept the length of the string, string, length js intercept the length of the string (Chinese and English)

js, intercept the length of the string, string, length js intercept the length of the string (Chinese and English)

巴扎黑
Release: 2016-11-25 13:58:27
Original
1248 people have browsed it

js intercepts the length of the string. When intercepting, the Chinese is calculated as 2 bytes.

function worldLimit(className, factLength){

$('.'+className).each(function(){
var content = $(this ).text();
var allLength = 0;
for (var i = 0; i < content.length; i++) {
var c = content.charCodeAt(i);
//Single byte plus 1
if ((c >= 0x0001 && c <= 0x007e) || (0xff60 <= c && c <= 0xff9f)) {
                                                                                                         1
                                                                                                                                                                                                                                    0; i < content.length; i++) {
        var c = content.charCodeAt(i);
                                                                                                                                                                            subLength++ ;
                                                                                                                                          ;
                                                                                                                                                                                 
             }
}
                $(this).text(subContent);                                                                                                         $(this).

Related labels:
js
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
Latest Issues
Where is js written?
From 1970-01-01 08:00:00
0
0
0
js file code not found
From 1970-01-01 08:00:00
0
0
0
js addClass not working
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template