Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/469.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用javascript在html中键入文本框的限制_Javascript_Html - Fatal编程技术网

使用javascript在html中键入文本框的限制

使用javascript在html中键入文本框的限制,javascript,html,Javascript,Html,我想寻求一些帮助…我的问题是我的脚本限制了除数字以外的所有内容…我想做的是…我可以键入双数字…比如1.232…我不想限制点…有人能帮我吗 当前代码: <input autocomplete="off" class="search_form_input" name="optA1" id="optA1" onkeypress="return isnumeric(event)" type="text" onchange="optTotal1()" /> 脚本代码: <script

我想寻求一些帮助…我的问题是我的脚本限制了除数字以外的所有内容…我想做的是…我可以键入双数字…比如1.232…我不想限制点…有人能帮我吗

当前代码:

<input autocomplete="off" class="search_form_input" name="optA1" id="optA1" onkeypress="return isnumeric(event)" type="text" onchange="optTotal1()" />
脚本代码:

<script type="application/javascript">

  function isnumeric(evt)
      {
         var CharacterCode = (evt.which) ? evt.which : event.keyCode

         if (CharacterCode > 31 && (CharacterCode < 48 || CharacterCode > 57))
            return false;

         return true;
      }

</script>
<>我会考虑一个ReXPp:< /P> var x=document.getElementByIdoptA1.value; 返回/[\d\.]+/.testx

或者,您可以通过函数传递值并以这种方式使用它。

类似于:

$('input').on('keydown', function(e) {
    var dot = $(this).val().indexOf('.');
    if((e.which >= 48 && e.which <= 57) ||
       (e.which >= 96 && e.which <= 105) ||
        ((e.which == 190 || e.which == 110) && dot == -1)
        ) return true;
    return false;
});
这也会检查你的numpad,如果你已经有了一个新的。以你的价值


添加alertCharacterCode;定义后,刷新页面,键入a。在输入中,记录数字,添加&&CharacterCode!=如果您的if语句中的X是您记录的数字,请删除您的警报。不确定,但您的代码允许我键入的不仅仅是数字。也许可以看看这里的一些建议:这行不通,字符代码将始终通过,因为它是一个数字。哎呀,我以为字符代码就是实际的字符!我会更新的!