jQuery Validation using the class instead of the name value

前端 未结 7 1230
清酒与你
清酒与你 2020-11-29 00:09

I\'d like to validate a form using the jquery validate plugin, but I\'m unable to use the \'name\' value within the html - as this is a field also used by the server app. Sp

相关标签:
7条回答
  • 2020-11-29 01:04

    Since for me, some elements are created on page load, and some are dynamically added by the user; I used this to make sure everything stayed DRY.

    On submit, find everything with class x, remove class x, add rule x.

    $('#form').on('submit', function(e) {
        $('.alphanumeric_dash').each(function() {
            var $this = $(this);
            $this.removeClass('alphanumeric_dash');
            $(this).rules('add', {
                alphanumeric_dash: true
            });
        });
    });
    
    0 讨论(0)
提交回复
热议问题