Home > Article > Web Front-end > js intercepts string length (Chinese, English)
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);