Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
移动图像。。。javascript将变量声明为字符串_Javascript_Variables - Fatal编程技术网

移动图像。。。javascript将变量声明为字符串

移动图像。。。javascript将变量声明为字符串,javascript,variables,Javascript,Variables,单击按钮时,包含位置的变量将声明为字符串! 这是html代码: 下面是javascript代码: 这一行有问题: pxMove=(Math.random()*10).toFixed(); toFixed将数字转换为字符串,然后下一行的加号运算符将对其进行concat而不是求和。如果要将其舍入并转换为整数,可以使用Math.round: pxMove = Math.round(Math.random() * 10); 请参阅,同时请明确说明您的代码目前没有做您希望它做的事情。

单击按钮时,包含位置的变量将声明为字符串! 这是html代码: 下面是javascript代码:

这一行有问题:

pxMove=(Math.random()*10).toFixed();
toFixed
将数字转换为字符串,然后下一行的加号运算符将对其进行concat而不是求和。如果要将其舍入并转换为整数,可以使用
Math.round

pxMove = Math.round(Math.random() * 10);
请参阅,同时请明确说明您的代码目前没有做您希望它做的事情。