2011-08-27 20:09
浏览 75


I am having trouble with a form that displays results drawn out of a mysql database, based on a user supplied string.

An order form, so to say. And in this form there is a quantity field. I have tried to use javascript to block all input except for numeric values. Along with this though, I have disabled the enter key functionality.

I know that this keycode is 23. But how do I allow a user may press enter to submit the form, working with the following peice of code:

onkeydown="return ( event.ctrlKey || event.altKey 
                || (47<event.keyCode && event.keyCode<58 && event.shiftKey==false) 
                || (95<event.keyCode && event.keyCode<106)
                || (event.keyCode==8) || (event.keyCode==9) 
                || (event.keyCode>34 && event.keyCode<40) 
                || (event.keyCode==46) )"

Any input with this would be greatly appreciated, thanks.

图片转代码服务由CSDN问答提供 功能建议


订单表格,可以这么说。 在这种形式中有一个数量字段。 我试图使用javascript来阻止除数字值之外的所有输入。 除此之外,我已经禁用了输入密钥功能。

我知道这个密钥代码是23.但是如何允许用户按Enter键提交表单,使用 下面的代码:

  onkeydown =“return(event.ctrlKey || event.altKey 
 ||(47&lt; event.keyCode&amp;&amp; event.keyCode&lt;  58&amp;&amp; event.shiftKey == false)
 ||(95&lt; event.keyCode&amp;&amp; event.keyCode&lt; 106)
 ||(event.keyCode == 8)||(event.keyCode  == 9)
 ||(event.keyCode&gt; 34&amp;&amp; event.keyCode&lt; 40)
 ||(event.keyCode == 46))“


  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doufu1970 2011-08-27 20:22

    I think this might help you:

    <!DOCTYPE html>
            <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script>
            <script type="text/javascript">
                $(function() {
                    $('#numeric').keydown(function(e) {
                        return ((e.keyCode >= 48 && e.keyCode <= 57) || e.keyCode == 13)
            <form method="post" action="">
                <input type="text" id="numeric" />
    解决 无用
    打赏 举报

相关推荐 更多相似问题