JQuery.validate的数字规则不适用于数字输入(digits rule of JQuery.validate not working on numeric input)

编程入门 行业动态 更新时间:2024-10-24 04:48:23
JQuery.validate的数字规则不适用于数字输入(digits rule of JQuery.validate not working on numeric input)

我在输入Html元素中有一个表单:

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

并且它的'type'属性设置为“number”,因为我想利用HTML5的功能。

在我的js代码中,我初始化jQuery.validate插件:

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

...但它不起作用..我已经正确管理了所有内容:我确信这是因为如果我从输入的'type'属性中取消(或将其设置为“text”),则验证工作正常。

这是jQuery.validate插件的错误还是我不小心错过了一些重要的东西?

感谢大家 ;)

I've got a form, within an input Html element:

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

and its 'type' attribute is set to "number" because I want to take advantage of HTML5's features.

In my js code I initialize jQuery.validate plugin:

$('.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.

Is it a bug of jQuery.validate plugin or am I carelessly missing something important?

Thanks everyone ;)

最满意答案

此问题之前已经确定,并且据称已修复......

你可以在这里阅读: https : //github.com/jzaefferer/jquery-validation/issues/97和这里: https : //github.com/jzaefferer/jquery-validation/pull/145

然而,似乎其他人最近报道(上述“修复”大约是2年,而本期报告是在过去的几个月内),所以它可能会再次被打破: https : //github.com/jzaefferer/ jQuery的验证/问题/ 922

我发现的唯一解决方法是在input元素上使用type="text" 。 这是不幸的,因为那样你最终得到纯文本输入而不是漂亮的HTML5整数框。

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

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

The only work-around I've found is to use type="text" on the input element. This is unfortunate because then you end up with the plain text input rather than the nice HTML5 integer box.

更多推荐

本文发布于:2023-08-07 09:40:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1463799.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数字   不适用于   规则   validate   JQuery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!