Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 查找文本不包含字符串的所有跨度元素_Jquery - Fatal编程技术网

Jquery 查找文本不包含字符串的所有跨度元素

Jquery 查找文本不包含字符串的所有跨度元素,jquery,Jquery,我正在尝试查找属于其text()值不包含字符串部分的特定类的所有元素 这就是我迄今为止所尝试的: if ($("#details .error").not($(this).text().contains("This schedule is used")).length == 0) { //do something } else { //do something else } 但是我得到一个无法读取未定义的属性“0”的错误。 有什么帮助吗?试试这个:您不需要使用$(this

我正在尝试查找属于其
text()
值不包含字符串部分的特定类的所有
元素

这就是我迄今为止所尝试的:

if ($("#details .error").not($(this).text().contains("This schedule is used")).length == 0) {
    //do something
}
else {
    //do something else   
}
但是我得到一个
无法读取未定义的属性“0”的错误。

有什么帮助吗?

试试这个:您不需要使用
$(this)
,而是在选择器中使用
包含()
非()

if ($("#details .error:not(:contains(This schedule is used))").length == 0) {
    //do something
}
else {
    //do something else   
}
或者您也可以使用
filter()


如果“作用域”中没有此
,请再次使用选择器

if ($("#details .error").not($("#details .error").text().contains("This schedule is used")).length == 0) {
    //do something
}
else {
    //do something else   
}

如果
span
元素包含
error
类,则没有
this
。可能是
$(“#details.error”)。不是(“:has(:contains(this schedule is used))”)。长度
-但是如果没有看到您的HTML,就无法提供完整的答案,
span
元素包含
error
类。您能给出一个html的示例吗!谢谢布山,时间一过,我会马上回复你的。是的,当然。很高兴能帮助您:)@RudolfLamprecht很好地使用了
filter()
!我没想过那件事。但是为什么
indexOf
而不是
$。contains
?@AndreasFurster,是的,我们也可以使用
.contains
,但只是将
indexOf
作为另一个选项。
if ($("#details .error").not($("#details .error").text().contains("This schedule is used")).length == 0) {
    //do something
}
else {
    //do something else   
}