Home > Web Front-end > JS Tutorial > js intercepts string length (Chinese, English)

js intercepts string length (Chinese, English)

巴扎黑
Release: 2016-12-06 13:33:12
Original
896 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);                                                                                                                                                                        

Related labels:
js
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