Home > front end >  For bosses to ask
For bosses to ask

Time:09-24

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);

CodePudding user response:

reference 1/f, the sky wave 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);

Oh oh, instantly understood, thank you for your bosses
  • Related