我收到未定义的未捕获类型错误,不是.empty()方法上的函数。该代码是
title: "Criteria: "+ (criteriaText.empty() ? (criteriaIncludeText.empty()? criteriaExcludeText : criteriaIncludeText) : criteriaText)
在上面的代码中criteriaText和criteriaIncludeText具有值。我可以在警报消息中看到这一点。使用的jQuery版本是1.7。我真的不确定为什么当有适当的值时,为什么会给未定义的未定义类型错误不是一个函数。有人可以帮忙吗?
编辑
这些变量通过以下代码获取其值。
var criteriaText = jQuery(".categorySelect option[value='"+categoryId+"']").text();
var criteriaIncludeText = jQuery(".categorySelectInclude option[value='"+categoryId+"']").text();
var criteriaExcludeText = jQuery(".categorySelectExclude option[value='"+categoryId+"']").text();
您正在尝试对字符串(而不是HTML DOM元素)使用jQuery的empty
方法:
例如:
var criteriaText = jQuery(".categorySelect option[value='"+categoryId+"']").text();
但是,jQuery不在字符串上提供该方法,因此您试图执行()
一个不存在的功能(又名jQuery的原型链未提供)。
似乎您只想检查该值是否为空(在您的三元语句中):
title: "Criteria: "+ (criteriaText.empty() ? (criteriaIncludeText.empty()? criteriaExcludeText : criteriaIncludeText) : criteriaText)
但是,jQuery的empty()
方法“从DOM中删除匹配元素集的所有子节点”并返回对象jQuery
(其值为true):
alert($('#elementId').empty()?'yes':'no');
// object jQuery is an object, object coerces to TRUE
现在,您很幸运,因为已将空字符串强制转换为false
,因此您可以.empty()
在三元组中省去部分工作!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句