Jquery 验证不起作用

发布于 2024-12-24 16:50:38 字数 409 浏览 3 评论 0原文

我正在尝试在使用两个日期选择器“ effectiveDate”和“ termDate”的表单上使用 Jquery 验证。生效日期不得早于期限日期。日期选择器可以工作,但当我违反验证时,不会显示任何错误。

<script language="javascript" type="text/javascript">
    jQuery(document).ready(function () {
        $("form").validate();
        var term = $("#TermDate").val();
        $("#EffectiveDate").datepicker({
            minDate: term
        });
    });
</script>

I'm trying to use Jquery validations on a form that uses two datepicker "effectiveDate" and "termDate". EffectiveDate must not be prior to TermDate. The datepicker works but there are not any errors being display when I violate the validation.

<script language="javascript" type="text/javascript">
    jQuery(document).ready(function () {
        $("form").validate();
        var term = $("#TermDate").val();
        $("#EffectiveDate").datepicker({
            minDate: term
        });
    });
</script>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遮云壑 2024-12-31 16:50:38

您需要应用验证规则 (dpDate),如本文:

jQuery(document).ready(function () {
    $("form").validate({
        rules: {
            // EffectiveDate is the name of the input, not the id
            // so make sure that the input is defined like this:
            // <input type="text" id="EffectiveDate" name="EffectiveDate" />
            EffectiveDate: {
                required: true,
                dpDate: true
            }
        }
    });

    var term = $("#TermDate").val();
    $("#EffectiveDate").datepicker({
        minDate: term
    });
});

要使此规则生效,您必须将 jquery.ui.datepicker.validation.js 扩展添加到您的页面。

You need to apply a validation rule (dpDate) as explained in this article:

jQuery(document).ready(function () {
    $("form").validate({
        rules: {
            // EffectiveDate is the name of the input, not the id
            // so make sure that the input is defined like this:
            // <input type="text" id="EffectiveDate" name="EffectiveDate" />
            EffectiveDate: {
                required: true,
                dpDate: true
            }
        }
    });

    var term = $("#TermDate").val();
    $("#EffectiveDate").datepicker({
        minDate: term
    });
});

For this rule to take effect you must add the jquery.ui.datepicker.validation.js extension to your page.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文