A cópia do código é a seguinte:
// Obtenha o comprimento do byte da corda
função len (s) {
s = string (s);
Retorno S.Length + (S.Match (/[^/x00-/xff]/g) || "") .Length; // Adicione o comprimento do caractere de largura total correspondente
}
Limite de função (obj, limite) {
var val = obj.value;
if (len (val)> limite) {
val = val.substring (0, limite);
while (len (val)> limite) {
val = val.substring (0, val.length - 1);
};
obj.value = val;
}
}
$ ("#apelido"). KeyUp (function () {
limite (este, 20); // dentro de 20 bytes
})