jquery validate name相同通过id验证

     $(function () {
            if ($.validator) {
                //fix: when several input elements shares the same name, but has different id-ies....
                $.validator.prototype.elements = function () {
                    var validator = this,
                        rulesCache = {};
                    // select all valid inputs inside the form (no submit or reset buttons)
                    // workaround $Query([]).add until http://dev.jquery.com/ticket/2114 is solved
                    return $([]).add(this.currentForm.elements)
                        .filter(":input")
                        .not(":submit, :reset, :image, [disabled]")
                        .not(this.settings.ignore)
                        .filter(function () {
                            var elementIdentification = this.id || this.name;
                            !elementIdentification && validator.settings.debug && window.console && console.error("%o has no id nor name assigned", this);
                            // select only the first element for each name, and only those with rules specified
                            if (elementIdentification in rulesCache || !validator.objectLength($(this).rules()))
                                return false;
                            rulesCache[elementIdentification] = true;
                            return true;
                        });
                };
            }
        });

 

posted @ 2017-08-02 16:23  sunniejs  阅读(455)  评论(0编辑  收藏  举报