Jquery. Validate introduction-4

Source: Internet
Author: User
By default, the label element is used to display the verification prompt information and CSS class is added, CSS allows you to easily set error controls and display methods of error messages. /* Input control verification error */form input. error {border: solid 1px red;}/* verification error message */form label. error {width: 200px; margin-left: 10px; color: red;} to customize the display mode, you can modify jquery. by default, the error message is displayed by label in validate. You can use the errorelement attribute to modify errorelement: the HTML tag of the error message $ (". selector "). validate errorelement: "em"}) You can use other element packaging layers in the error message. Wrapper: the outer HTML tag of the error message $ (". selector "). validate ({wrapper: "Li"}) the default error CSS class for verification is error. errorclass can be used to modify errorclass: the CSS class $ (". selector "). validate ({errorclass: "invalid"}) also customizes the success action when the verification is successful: If the value is a string, it is treated as a CSS class. If it is a function, then execute this function $ (". selector "). validate ({success: "valid"}) or success: function (Label) using label.html (""). addclass ("checked");} can also unify the error message to a container to display errorlabelcontainer: unify the error message to a container to display $ ("# myform "). validate ({errorlabelcontainer: "# MessageBox"}) by default, the error message is placed after the verification element. You can customize the display position of the error message $ (". selector "). validate ({errorplacement: function (error, element) {error. appendto (element. parent ("TD "). next ("TD");}) You can define a group to unify the error information in several places and use the error placement to control where the error information is put. Groups: define a group $ (". selector "). validate ({groups: {Username: "fname lname"}, errorplacement: function (error, element) {If (element. ATTR ("name") = "fname" | element. ATTR ("name") = "lname") error. insertafter ("# lastname"); else error. insertafter (element) ;}}) highlighted highlight: highlighted. By default, errorclassunhighlight is added, which corresponds to highlight (". selector "). validate ({highlight: function (element, errorclass) {$ (element ). addclass (errorclass); $ (element. form ). find ("Label [for =" + element. ID + "]"). addclass (errorclass) ;}, unhighlight: function (element, errorclass) {$ (element ). removeclass (errorclass); $ (element. form ). find ("Label [for =" + element. ID + "]"). removeclass (errorclass) ;}}); or you can customize showerrors for an error: Get the error display handle $ (". selector "). validate ({showerrors: function (errormap, errorlist) {$ ("# summary" ).html ("Your form contains" + this. numberofinvalids () + "errors, see details below. "); this. defaultshowerrors ();}})

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.