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


網站后台用了JQuery Validate框架,版本是jQuery Validation Plugin 1.8.1

因為用的時間比較久了,一直沒有更新新版本。

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

第688行報錯:name為null。

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

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

現在將其取消注釋,這段代碼上面描述的意思是:只選擇符合每個名字的第一個元素,並且僅選擇指定了rules的元素。

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

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;
            });
        },

 

 

參考文章:

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM