gpt4 book ai didi

javascript - 我收到未捕获的 TypeError : Cannot read property 'length' of null on jquery. main.js

转载 作者:行者123 更新时间:2023-11-28 07:49:06 24 4
gpt4 key购买 nike

这一行:

this.textActive = this.focused || (this.element.value.length && this.element.value !== this.origValue);

正在生成此错误消息:未捕获类型错误:无法读取 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);

关于javascript - 我收到未捕获的 TypeError : Cannot read property 'length' of null on jquery. main.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27073232/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com