问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/11530208/cannot-break-on-jquery-validate-callbacks