Home > Web Front-end > JS Tutorial > body text

How jquery validate prompts errors

coldplay.xixi
Release: 2020-11-18 10:01:46
Original
1934 people have browsed it

jquery validate prompts an error method: quote [], The custom method is extended to [$.validator].

How jquery validate prompts errors

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>
Copy after login
$.extend($.validator.defaults, {
            showErrors: function (errorMap, errorList) {
                var msg = "";
                $.each(errorList, function (i, v) {
                    msg += (v.message + "\r\n");
               });
           if (msg != "")
                   alert(msg);
            }
       });
Copy after login

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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!