用JQuery Validate框架,在IE8下驗證報錯問題解決

網站後臺用了JQuery Validate框架,版本是jQuery Validation Plugin 1.8.1html

由於用的時間比較久了,一直沒有更新新版本。jquery

最近公司信息錄入員有調整,沒有IE11瀏覽器,使用IE8報錯,報錯位置以下:瀏覽器

第688行報錯:name爲null。框架

找了好多資料,最終找到合適的解決方案以下,在jquery.validate.js文件中找到elements方法,原來註釋掉了這段代碼:ide

1 if ( this.name in rulesCache || !validator.objectLength($(this).rules()) )
2                     return false;

如今將其取消註釋,這段代碼上面描述的意思是:只選擇符合每一個名字的第一個元素,而且僅選擇指定了rules的元素。網站

若是沒有這段代碼,全部沒指定rules的元素都會被驗證,但大部分都是沒有name的,這樣就會致使上述的問題。js報錯致使沒法保存。this

elements: function() {
            var validator = this,
                rulesCache = {};

            // select all valid inputs inside the form (no submit or reset buttons)
            return $(this.currentForm)
            .find("input, select, textarea")
            .not(":submit, :reset, :image, [disabled]")
            .not( this.settings.ignore )
            .filter(function() {
                var elementIdentification = this.id || this.name; 
                
                !this.name && validator.settings.debug && window.console && console.error( "%o has no name assigned", this);

                // select only the first element for each name, and only those with rules specified
                if ( this.name in rulesCache || !validator.objectLength($(this).rules()) )
                    return false;

                //rulesCache[this.name] = true;
                
                rulesCache[elementIdentification] = true; 
                return true;
            });
        },

 

 

參考文章:spa

http://www.docin.com/p-908202951.htmldebug

相關文章
相關標籤/搜索