Home >Web Front-end >JS Tutorial >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 var c = content.charCodeAt(i);
//Single byte plus 1
if ((c >= 0x0001 && c 1
0; i var c = content.charCodeAt(i);
subLength++ )
}
}
$(this).text(subContent);