Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.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,我想从这个元素(“饮料”)中提取文本: 假设它是整个html中列表项中唯一的锚标记 这样,$('li a').html()似乎您想要将.breadcrumb元素的最后一个a文本作为类添加到html元素中,您可以使用addClass来添加类,并且.last()选择面包屑最后一个a后代的方法 $('html').addClass(function() { return $('.breadcrumb a').last().text().toLowerCase(); }); 这个元素有什么特别之

我想从这个元素(“饮料”)中提取文本:


假设它是整个html中列表项中唯一的锚标记


这样,
$('li a').html()

似乎您想要将
.breadcrumb
元素的最后一个
a
文本作为类添加到
html
元素中,您可以使用
addClass
来添加类,并且
.last()
选择面包屑最后一个
a
后代的方法

$('html').addClass(function() {
   return $('.breadcrumb a').last().text().toLowerCase();
});

这个元素有什么特别之处?这是该列表中唯一的<代码> <代码>,或者是列表中的第二个,还是列表中的最后一个,或者其他什么?请考虑改写你的问题。
$('html').addClass(function() {
   return $('.breadcrumb a').last().text().toLowerCase();
});