Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Js control string length is 4, if it is not enough, add spaces! !
Js control string length is 4, if it is not enough, add spaces! !
The following code is written with JS tag. Let's test it. If 4 digits are not enough, add a space after it. For example, take 123 as an example:

var str = " 123 ";

if(str . length & lt; 4){

for(var I = 0; I < (4-string length); i++){

str+= " ";

}

}

if(str . length & gt; =4){

str = str.substring(0,4);

}

document . write(str);