无法打破jquery.validate回调 [英] Cannot break on jquery.validate callbacks

查看:166
本文介绍了无法打破jquery.validate回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Firefox / Firebug,尝试逐步浏览一些jquery.validate()回调。



为什么在下面的断点 //断点线不会在点击提交按钮时触发?

 <!DOCTYPE html> ; 
< head>
< script type =text / javascriptsrc =/ library / scripts / lib / jquery-1.7.2.js>< / script>
< script type =text / javascriptsrc =/ Scripts / jquery.validate.js>< / script>
< script type =text / javascriptsrc =/ Scripts / jquery.validate.unobtrusive.js>< / script>
< / head>
< body>
< form action =/method =post>
< input data-val =truedata-val-required =这是必需的id =BirthDate
name =BirthDatetype =textvalue =/> ;
< span class =field-validation-validdata-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!)//断点
},
invalidHandler:function(form,validator){
alert(Invalid!)// Breakpoint
}
})
});
< / script>
< / body>
< / html>

更新



<实际上,似乎没有任何validate()选项生效。例如,我已经将 debug:true 添加到上面的示例中,并根据文档来防止提交表单,并且仍在提交表单。没有任何警报也被触发。



但是,我已经确认validate()函数被调用,因为我可以一步一步 - 只是不回调

解决方案

不幸的是,jquery.validate()选项似乎不起作用与非显着性验证结合使用时。从我的文件中删除该引用可以解决这个问题,但是当然会打破我不明智的验证。



所以我最终使用了另一个解决方案挂钩到验证事件。


I'm using Firefox/Firebug, trying to step through some of the jquery.validate() callbacks.

Why do breakpoints on the below // Breakpoint lines not trigger upon clicking the submit button?

<!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. 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. 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.

解决方案

Unfortunately, the jquery.validate() options don't seem to function when used in combination with unobtrusive validation. 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.

这篇关于无法打破jquery.validate回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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