When writing JS code, you can find this phenomenon:
document.write(" 1 2 3 ");Result: 1 2 3No matter how many spaces there are in the output content, the displayed result seems to have only one space.
This is because the browser display mechanism displays multiple spaces manually tapped into it to 1 space.
Solution:
1. Use the output html tag to solve it
document.write(""+"1"+""+"23");Result: 1 232. Use CSS style to solve
document.write("<span style='white-space:pre;'>"+" 1 2 3 "+"</span>");Result: 1 2 3Add the "white-space:pre;" style attribute when output. This style means "Blank will be retained by the browser"
The simple implementation method of JS output spaces above is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.