Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.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 如何将Math.round放入函数并限制用户输入int?_Javascript_Html - Fatal编程技术网

Javascript 如何将Math.round放入函数并限制用户输入int?

Javascript 如何将Math.round放入函数并限制用户输入int?,javascript,html,Javascript,Html,代码如下: <script> function doAll(x) { } </script> <input type="number" oninput="this.value = Math.round(this.value);doAll(this.value);"> this.value = Math.round(this.value); 进入功能。因此,它将是: <input type="num

代码如下:

<script>
function doAll(x) {

}
</script>

<input type="number" oninput="this.value = Math.round(this.value);doAll(this.value);">
this.value = Math.round(this.value);
进入功能。因此,它将是:

<input type="number" oninput="doAll(this.value);">

我所做的:

<script>
function doAll(x) {
    x = Math.round(x);
}
</script>

<input type="number" oninput="doAll(this.value);">

函数doAll(x){
x=数学圆(x);
}
函数的calc工作。但在此之后,用户的输入不再受限。
如何解决此问题?

您不再设置
此值。您正在设置复制的值(
x
)。请尝试以下操作:

函数doAll(e){
x=数学四舍五入(e值);
e、 值=x;
}

好主意,我需要设置值。但是这个值=x;不起作用。糟糕,我更新了一个完全起作用的示例的答案。我只是尝试设置id并使用jquery。但是你的更好。谢谢。:)