jquery validate prompts an error method: quote [], The custom method is extended to [$.validator].
Recommendation: "jquery video tutorial"
jquery validate prompts error method:
Modify the jquery.validate prompt error method and use a pop-up box to prompt the error message
<script src="@Url.Content("~/Scripts/jquery.validate.js")"></script> <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")"></script>
$.extend($.validator.defaults, { showErrors: function (errorMap, errorList) { var msg = ""; $.each(errorList, function (i, v) { msg += (v.message + "\r\n"); }); if (msg != "") alert(msg); } });
After the modification, it was found that the execution had no effect and the error message would not pop up. The message was still behind the text box. Display
After debugging, it was found that the custom method was not extended to $.validator
,
and for the overridden method to work, it must be referenced
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")"></script>
It can only be rewritten before.
The complete code is as follows:
<script src="@Url.Content("~/Scripts/jquery.validate.js")"></script> <script type="text/javascript"> $.extend($.validator.defaults, { showErrors: function (errorMap, errorList) { var msg = ""; $.each(errorList, function (i, v) { msg += (v.message + "\r\n"); }); if (msg != "") alert(msg); } }); </script> <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")"></script>
Related free learning recommendations: JavaScript (video)
The above is the detailed content of How jquery validate prompts errors. For more information, please follow other related articles on the PHP Chinese website!