移动图像... javascript将变量声明为字符串(Moving an image … javascript declare variables as string)
单击按钮时,包含位置的变量将声明为字符串! 这是html代码: http : //insane96mcp.altervista.org/corsa.html这里是javascript代码: http : //insane96mcp.altervista.org/corsa.js
When you click a button the variable which contains the position is declared as string! This is the html code: http://insane96mcp.altervista.org/corsa.html And here's the javascript code: http://insane96mcp.altervista.org/corsa.js
最满意答案
问题出在这一行:
pxMove=(Math.random()*10).toFixed();toFixed将您的数字转换为字符串,然后下一行中的加号运算符将连接它而不是求和。 如果要将其舍入并转换为整数,可以使用Math.round :
pxMove = Math.round(Math.random() * 10);The problem is with this line:
pxMove=(Math.random()*10).toFixed();toFixed will convert your number to string, and the plus operator in the next line will then concat it instead of summing. If you want to round it and transform to integer, you can use Math.round:
pxMove = Math.round(Math.random() * 10);更多推荐
发布评论