keyfilter

Limit input box to 0-100

家住魔仙堡 提交于 2019-11-27 08:23:58
I have an input box that takes values from 0-100. I want to prevent users from writing anything larger or smaller. I've been using the jquery keyfilter plugin to limit the input of a field: http://code.google.com/p/jquery-keyfilter/ This plugin can limit the input to numerals, but not within a range. How do I prevent users from entering numbers that would exceed the range. Thanks. Use plain Javascript like this: <script> function handleChange(input) { if (input.value < 0) input.value = 0; if (input.value > 100) input.value = 100; } </script> Then declare the input box like this: <input type=

Limit input box to 0-100

99封情书 提交于 2019-11-27 04:28:35
问题 I have an input box that takes values from 0-100. I want to prevent users from writing anything larger or smaller. I've been using the jquery keyfilter plugin to limit the input of a field: http://code.google.com/p/jquery-keyfilter/ This plugin can limit the input to numerals, but not within a range. How do I prevent users from entering numbers that would exceed the range. Thanks. 回答1: Use plain Javascript like this: <script> function handleChange(input) { if (input.value < 0) input.value = 0