【问题标题】:How to restrict the value inside a textbox for a range of values from 1-999 using javascript如何使用javascript限制文本框中的值范围为1-999
【发布时间】:2015-02-19 10:35:21
【问题描述】:

我希望有一个文本框,它使用 javascript 接受 1-999 之间的数值,并且必须使用 keypress 事件,因为不应允许 uswr 在文本框中输入 o,但说 foreg 106 应该是允许的值。目前我可以限制 0 然后它不允许用户为以后的数字输入 0 也因为它不允许输入 105 我正在使用 icefaces 所以不能在这里使用 html5 而且必须使用 js 和使用 onkeypress 事件作为用户来实现甚至不允许输入值

代码 sn-p 如下,我使用过 onkeypress="if(event.which 57) return false;

【问题讨论】:

    标签: javascript


    【解决方案1】:

    试试这个方法……

    <script type="text/javascript">
        function validateRange() {
            var txtVal = document.getElementById("<%=TextBox1.ClientID%>").value;
            if (txtVal >= 1 && txtVal <= 999) {
                return true;
            }
            else
                alert('Please enter a number between 1-999');//Also you can set this message to an existing label
                return false;
        }
    </script>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-19
      • 2013-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多