输入类型数字小数在Firefox中不接受

时间:2018-06-21 06:45:24

标签: javascript html html5 firefox mozilla

input[type='number'] {
  -moz-appearance: textfield !important;
}

.no-spin::-webkit-inner-spin-button,
.no-spin::-webkit-outer-spin-button {
  -webkit-appearance: none !important;
  margin: 0 !important;
}

.input::-webkit-inner-spin-button,
.input::-webkit-outer-spin-button {
  -webkit-appearance: none !important;
  margin: 0 !important;
}
<input type="number" oninput="this.value = this.value.replace(/[^0-9.]/g,'')" lang="en">

我无法使Firefox 60.0.2接受期间(.)输入十进制数字。但是在chrome中也是如此。即使删除了样式,这也不起作用。

如何使用文本或数字类型(最好是数字类型)编写正确的html输入标签,以便接受十进制输入

1 个答案:

答案 0 :(得分:2)

为什么不只使用type = text,因为您已经有了只允许小数的脚本?

<input type="text" oninput="this.value = this.value.replace(/[^0-9\.]/g, '').split(/\./).slice(0, 2).join('.')" lang="en">

相关问题