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。但是你的更好。谢谢。:)