Input number does not limit decimal when “0” is typed

蹲街弑〆低调 提交于 2019-12-13 08:27:34

问题


I have a scenario where the HTML input field must take only 16 digit where 6 of its digits will be allocated for decimal places, but one strange thing happend in the code below is, when I add "0" at the end of decimal values, the digits are not being restricted and it keeps increasing. Is there anything that I'm missing out here?

<input type="number" name="val" min=0 max=9999999999.999999 step=".000001" save="" oninput="validity.valid ? this.save = value : value = this.save;"

回答1:


Resolved the issue with the following code

<input type="number" name="val" min=0 max=9999999999.999999 step=".000001" save="" oninput="validity.valid && ((value.toString()).split('.')[1] === undefined || ((value.toString()).split('.')[1].length < 6)) ? this.save = value : value = this.save"/>


来源:https://stackoverflow.com/questions/55119386/input-number-does-not-limit-decimal-when-0-is-typed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!