Home >Web Front-end >JS Tutorial >JS controls the length of the string in the input box_javascript skills
function limit(obj, limit) {
var val = obj.value;
if (len(val) > limit) {
val=val.substring(0,limit);
while (len(val) > limit){
val = val.substring(0, val.length - 1);
};
obj.value = val;
}
}
$("#nickName").keyup(function(){
limit(this,20);//Within 20 bytes
})