Declaring jQuery Validate plugin rules — attribute vs. class vs. code

前端 未结 4 1728
眼角桃花
眼角桃花 2020-12-09 15:45

In the examples for the jQuery Validate plugin, I see three different approaches to declaring validation rules:

  • CSS Classes -- e.g.
4条回答
  •  长情又很酷
    2020-12-09 16:31

    You can apply rules trough data-rule attributes. This is the easiest way and possibly the best way to maintain a clean code...

    Example:

    You can even provide messages through data attributes:

    
    

    In JavaScript just call:

    $('#myform').validate();
    

提交回复
热议问题