I want to set the speed of 20 px for moving the red square, but I found that the rear block disappeared suddenly move is very, very fast, and then I added a alert found that see the red square on the left side of the distance from 20 px, 2020 px to 202020 px, excuse me, is this what is the row, thank you bosses answer
CodePudding user response:
Because speed is a string, If a plus sign (+) on both sides of a square is a string, will be the other party is automatically converted into a string, the string concatenation operation, Such as: 123 + "456" is equal to "123456"
You put the speed assignment for numerical can Var speed=parseInt (document. GetElementById (" text1 "). The value of 10);