![](/img/trans.png)
[英]I'm using focusin/ focusout and I'm getting: Uncaught TypeError: Cannot read property 'addEventListener' of null
[英]I'm getting an Uncaught TypeError: Cannot read property 'length' of null on jquery.main.js
这行:
this.textActive = this.focused || (this.element.value.length && this.element.value !== this.origValue);
正在生成此错误消息:未捕获的TypeError:无法读取null的属性“长度”
我不确定是什么原因造成的,但是却在造成问题。
refreshClasses: function() {
this.textActive = this.focused || (this.element.value.length && this.element.value !== this.origValue);
this.setStateClass(this.element, this.options.inputFocusClass,this.focused);
this.setStateClass(this.elementParent, this.options.parentFocusClass,this.focused);
this.setStateClass(this.labelFor, this.options.labelFocusClass,this.focused);
this.setStateClass(this.element, this.options.inputActiveClass, this.textActive);
this.setStateClass(this.elementParent, this.options.parentActiveClass, this.textActive);
this.setStateClass(this.labelFor, this.options.labelActiveClass, this.textActive);
},
setStateClass: function(el,cls,state) {
if(!el) return; else if(state) addClass(el,cls); else removeClass(el,cls);
}
}
在您的代码中,您尚未考虑到value
属性可能尚未定义,而不是检查长度,而是使用typeof
检查类型:
this.textActive = this.focused || (typeof this.element.value == 'undefined' && this.element.value !== this.origValue);
我也很喜欢这个。 @Nabil是正确的。 如果该值未定义,则自然不能有长度。
this.textActive = this.focused || this.element.value &&
this.element.value !== this.origValue;
这对您不起作用吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.