简体   繁体   English

无法中断jquery.validate回调

[英]Cannot break on jquery.validate callbacks

I'm using Firefox/Firebug, trying to step through some of the jquery.validate() callbacks. 我正在使用Firefox / Firebug,尝试逐步执行一些jquery.validate()回调。

Why do breakpoints on the below // Breakpoint lines not trigger upon clicking the submit button? 为什么以下// Breakpoint行上的// Breakpoint不会在单击“提交”按钮时触发?

<!DOCTYPE html>
<head>
    <script type="text/javascript" src="/library/scripts/lib/jquery-1.7.2.js"></script>
    <script type="text/javascript" src="/Scripts/jquery.validate.js"></script>
    <script type="text/javascript" src="/Scripts/jquery.validate.unobtrusive.js"></script>
</head>
<body>
    <form action="/" method="post">
    <input data-val="true" data-val-required="This is required" id="BirthDate" 
           name="BirthDate" type="text" value="" />
    <span class="field-validation-valid" data-valmsg-for="BirthDate" 
          data-valmsg-replace="true"></span>
    <p>
        <input type="submit" /></p>
    </form>
    <script type="text/javascript">
        $(document).ready(function () {
            $('form').validate({
                debug: true,
                submitHandler: function () {
                    alert("Submitted!") // Breakpoint
                },
                invalidHandler: function (form, validator) {
                    alert("Invalid!") // Breakpoint
                }
            })
        });
    </script>
</body>
</html> 

Update 更新

Actually, it doesn't seem like any of the validate() options are taking effect. 实际上,似乎没有任何validate()选项正在生效。 For example, I've added debug: true to the example above, and per the documentation it's supposed to prevent the form from being submitted, and it's still submitting the form. 例如,我在上面的示例中添加了debug: true ,并且按照文档的说明,它应该阻止表单提交,并且仍在提交表单。 None of the alerts are fired either. 也不会触发任何警报。

However, I have confirmed that the validate() function is getting called, because I can step through that -- just not the callbacks. 但是,我已经确认了validate()函数正在被调用,因为我可以逐步执行该过程-而不是回调。

Unfortunately, the jquery.validate() options don't seem to function when used in combination with unobtrusive validation . 不幸的是,jquery.validate()选项与非侵入式验证结合使用时似乎不起作用。 Removing that reference from my file fixes the issue, but of course, breaks my unobtrusive validation. 从我的文件中删除该引用可解决此问题,但当然会破坏我的验证能力。

So I ended up using another solution to hook into the validation events. 因此,我最终使用了另一种解决方案来挂接验证事件。

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

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