问题
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