当将step ="1"放入jQuery时,jQuery验证失败.在"datetime-local"中输入类型 [英] jQuery validation fails when putting step="1" in a "datetime-local" input type

查看:138
本文介绍了当将step ="1"放入jQuery时,jQuery验证失败.在"datetime-local"中输入类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 https://jqueryvalidation.org/表单验证插件

I'm using https://jqueryvalidation.org/ form validation plugin

当我将step="1"放在datetime-local输入字段中以显示秒数时,如果我正在使用插件验证该字段(例如,仅必需"),则会收到一个JavaScript错误,提示步骤属性为输入类型不支持datetime-local".如果我将step ="1"放在未经验证的字段中,则可以正常工作.

When I put step="1" in a datetime-local input field to show seconds, if I'm validating that field with the plugin (just "required", for example), I get a javascript error saying "Step attribute on input type datetime-local is not supported". If I put this step="1" in a field that is not being validated, it works without problems.

$("#testingform").validate();

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery-validation@1.17.0/dist/jquery.validate.min.js"></script>
<form id="testingform">
    <input type="datetime-local" step="1" name="date1" required>
    <button type="submit">Send</button>
</form>

...只需将日期和时间设置为秒",然后单击发送"按钮.您可以在控制台中看到错误.

... just put a date and time WITH SECONDS, and click 'Send' button. You can see the error in the console.

我已经在项目的github页面上打开了一个错误,但是也许你们中的任何一个都遇到了同样的问题,并且找到了解决它的方法,或者至少暂时避免了它,直到他们修复它为止.

I've already opened a bug in the github page of the project, but maybe any of you had the same problem and have found a way to solve it or at least avoid it for the moment until they fix it.

推荐答案

jQuery会自动将规则应用于输入类型,因此 step 不能得到验证.

jQuery validate automatically apply rules on input type, so step cannot be validated.

这将为您提供帮助:

$("#testingform").validate({
  rules: {
    date1: {step: false}
  }
});

<form id="testingform">
    <input type="datetime-local" step="1" name="date1" required>
    <button type="submit">Send</button>
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery-validation@1.17.0/dist/jquery.validate.min.js"></script>

这篇关于当将step ="1"放入jQuery时,jQuery验证失败.在"datetime-local"中输入类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆