用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

转载于:https://www.cnblogs.com/destimarve/p/5511257.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值