简体   繁体   English

JQuery.validate的数字规则不适用于数字输入

[英]digits rule of JQuery.validate not working on numeric input

I've got a form, within an input Html element: 我在输入HTML元素中有一个表单:

<input name="MyInputName" type="number" />

and its 'type' attribute is set to "number" because I want to take advantage of HTML5's features. 并将其“类型”属性设置为“数字”,因为我想利用HTML5的功能。

In my js code I initialize jQuery.validate plugin: 在我的js代码中,我初始化jQuery.validate插件:

$('.myFormClassName').validate({
   rules: {
      MyInputName: {
         digits: true
      }
   }
});

... but it does not work.. I've managed everything correctly: I'm sure of this because if I get off my input's 'type' attribute (or set it to "text"), the validation works fine. ...但是它不起作用。我已经正确地管理了所有事情:我敢肯定,因为如果取消输入的'type'属性(或将其设置为“ text”),则验证工作正常。

Is it a bug of jQuery.validate plugin or am I carelessly missing something important? 是jQuery.validate插件的错误,还是我粗心地错过了一些重要的东西?

Thanks everyone ;) 感谢大家 ;)

This issue has been identified before and was supposedly fixed... 这个问题之前已经被发现,并且可以解决。

You can read about it here: https://github.com/jzaefferer/jquery-validation/issues/97 and here: https://github.com/jzaefferer/jquery-validation/pull/145 您可以在这里阅读: https//github.com/jzaefferer/jquery-validation/issues/97和此处: https//github.com/jzaefferer/jquery-validation/pull/145

However, it appears others are reporting more recently (the above "fix" is around 2 years old, whereas this issue report is within the past few months) and so it may be broken again: https://github.com/jzaefferer/jquery-validation/issues/922 但是,似乎其他人正在报告较新的信息(上述“修复”大约有2年的历史,而此问题报告在过去几个月内),因此它可能会再次被破坏: https : //github.com/jzaefferer/ jQuery的验证/问题/ 922

The only work-around I've found is to use type="text" on the input element. 我发现的唯一解决方法是在输入元素上使用type="text" This is unfortunate because then you end up with the plain text input rather than the nice HTML5 integer box. 这很不幸,因为这样您最终将得到纯文本输入,而不是漂亮的HTML5整数框。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM