document.querySelectorAll('input').forEach(input => {
input.addEventListener("keydown", function(e) {
var charValue = String.fromCharCode(e.keyCode);
if (((!/^(d+)?([.]?d{0,1})?$/.test(this.value + e.key)) && (e.which != 8))) {
e.preventDefault()
}
})
})
SetPoint :<input id="input" type="text" name="setPoint" max="5" min="1" />
this block of code is a bit beyond my understanding but I'm guessing you use e.something and <= in the if statement to add a less than or equal to limit the number that the form will accept
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…