Javascript 迭代项目列表,如果项目的文本对应于;“什么?”;(使用jquery)

Javascript 迭代项目列表,如果项目的文本对应于;“什么?”;(使用jquery),javascript,jquery,html,css,Javascript,Jquery,Html,Css,我有一份物品清单,我想: 如果一个项目的文本对应于另一个文本,那么我必须添加一个带有类的span(类是图标字体) 奇怪的是,我把这个类添加到了所有的项目中,我不明白为什么 $('#block-system-main-menu li').each(function () { if (($(this).children().text()) == 'Mappe' || 'Vulc' || 'Equa'){ $(

我有一份物品清单,我想: 如果一个项目的文本对应于另一个文本,那么我必须添加一个带有类的span(类是图标字体)


奇怪的是,我把这个类添加到了所有的项目中,我不明白为什么

 $('#block-system-main-menu li').each(function () {
                if (($(this).children().text()) == 'Mappe' || 'Vulc' || 'Equa'){
                    $(this).append('<span class="fa fa-caret-right"></span>');
                }               
            });
$('#阻止系统主菜单li')。每个(功能(){
if($(this.children().text())=='Mappe'| | |'Vulc'| | |'Equa'){
$(此)。附加(“”);
}               
});

谢谢

请看下面的片段。您必须按如下方式检查每个文本:

$('#阻止系统主菜单li')。每个(功能(){
if($(this.children().text())='Mappe'| |$(this.children().text()='Vulc'| |$(this.children().text()='Equa'){
$(此)。附加(“”);
}               
});

因为您的条件满足所有场景。您需要在
条件下分离问题:

$('#block-system-main-menu li').each(function () {
   var text=$(this).find('a').text(); //get the a's text using find and store it as 
   //reference in variable
   if (text == 'Mappe' || text== 'Vulc' || text== 'Equa'){
        $(this).append('<span class="fa fa-caret-right"></span>');
   }               
});
$('#阻止系统主菜单li')。每个(功能(){
var text=$(this.find('a').text();//使用find获取a的文本并将其存储为
//变量中的引用
如果(text='Mappe'| | text='Vulc'| | text=='Equa'){
$(此)。附加(“”);
}               
});

希望这会有所帮助

$('#block-system-main-menu li').each(function () {
var _getCondition =$(this).children().text()
if (_getCondition == 'Mappe' || _getCondition == 'Vulc' || _getCondition== 'Equa'){
  $(this).append('<span class="fa fa-caret-right">Hello</span>');
   }               
$('#阻止系统主菜单li')。每个(功能(){
var_getCondition=$(this.children().text())
如果(_getCondition=='Mappe'| |(u getCondition=='Vulc'| |(u getCondition=='Equa')){
$(this.append('Hello');
}               
}))

在span中添加hello只是为了验证


随时。。。快乐编码…)
$('#block-system-main-menu li').each(function () {
var _getCondition =$(this).children().text()
if (_getCondition == 'Mappe' || _getCondition == 'Vulc' || _getCondition== 'Equa'){
  $(this).append('<span class="fa fa-caret-right">Hello</span>');
   }