Limit number input to range
问题 I want to limit a user input to a specific range (-90 to 90). Number can be integer or decimal. The default value must be 0 . I do not want to use HTML5 min / max attributes. This is my HTML: <input type="number" value="0" /> This is what I have tried: $('input').on('input', function () { var value = $(this).val(); $(this).val(Math.max(Math.min(value, 90), -90)); }); This is buggy because it doesn't let me erase the default value (therefore I cannot enter a - for a negative number or a . for