Version hint: JQ is 1.4.4, Jquery.validate is jquery validation plug-in 1.7
Problem:
A. Optional options, such as mailbox format verification, then the case input box, verify that the label becomes blank "The original default hint is gone"
B. Required options, such as mobile phone number directly copied in, the format is right, verify that the label is unchanged
1. master Page
$ (function () {$.validator.setdefaults ({errorclass:"Tip-error", errorplacement:function (Error, Element) {Error.prependto (element.parents ("TD"). Next ()); Objerror.removeclass ("Btn_infomust"); objerror.html (Error); }, Success:function (Element) {element.html ("correct"). AddClass ("tip-success"); } });});
2. Sample form page code
<tr> <th scope="Row">Mobile Number:</th> <td>@Html. Textboxfor (t= T.phoneno,New{@Style ="width:200px", maxlength =" -" }) </td> <TDclass="slight"> <labelclass="Btn-infomust"> Required fields. </label> </td> </tr> <tr> < Th scope="Row">e-mail address:</th> <td>@Html. Textboxfor (t= T.email,New{@Style ="width:200px", maxlength =" -" }) </td> <TDclass="slight"> <spanclass="Btn-info"> Optional fields. </span> </td> </tr>
3.jquery.validate.js File Code
Solution: Note that the code is written to death, the need to change according to their own
//before and after 360 linesif(element.value==""){if(Element). Rules (). Required! =true&&$ (Element). Rules (). Required! =false) {$ (Element). Parents ("TD"). Next ("TD"). HTML ('<label class= "Btn-info" > Optional. </label>');}} Element:function (Element) {//default prompt is restored when rule required does not exist if(Element.value = ="") { if(Element). Rules (). Required! =true&& $ (Element). Rules (). Required! =false) {$ (Element). Parents ("TD"). Next ("TD"). HTML ('<label class= "Btn-info" > Optional. </label>'); } } returnresult; } //before and after 670 linesshowlabel:function (element, message) {//Replace label manually$ (Element). Parents ("TD"). Next ("TD"). HTML (label); Console.log (label); This. Toshow = This. Toshow.add (label); },
Resolve Jquery.validate.js Validation Bugs