Validating multiple forms on the same page

前端 未结 6 381
面向向阳花
面向向阳花 2021-01-14 03:03

For example I have 3 forms in a page with the same names. How can I validate all these forms with one validate method?

6条回答
  •  囚心锁ツ
    2021-01-14 03:35

    Inspired by the answer of @Irshad Khan, hope it may help others. Apply data-rule-required="true" to required HTML inputs then in jQuery

    $('form').submit(function (e) {
            e.preventDefault();
            var clikedForm = $(this);
            if (clikedForm.valid()) {
                alert('valid');
            } else {
                alert('not_valid');
            }
        });
    

提交回复
热议问题