Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/437.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
Javascript Jquery循环通过每个ul的每个li_Javascript_Jquery_Html - Fatal编程技术网

Javascript Jquery循环通过每个ul的每个li

Javascript Jquery循环通过每个ul的每个li,javascript,jquery,html,Javascript,Jquery,Html,目前有一个这样的循环,它遍历每个li,在li中查找某些内容并添加一个类。问题是布局有多个UL,即,我希望它在每个UL中找到li。现在,它在找到任何符合我的IF条件的li时立即停止 var list = $('.sampleAddress li span'); $(list.get().reverse()).each(function () { var currentLine = $(this).html(); var unmatched = unmatchedLine; if

目前有一个这样的循环,它遍历每个li,在li中查找某些内容并添加一个类。问题是布局有多个UL,即,我希望它在每个UL中找到li。现在,它在找到任何符合我的IF条件的li时立即停止

 var list = $('.sampleAddress li span');
  $(list.get().reverse()).each(function () {
  var currentLine = $(this).html();
  var unmatched = unmatchedLine;
   if (currentLine.indexOf(unmatched) !== -1) {
       $(this).html($(this).text().replace("  ", " ").replace("&", "&AMP;").replace(unmatchedLine.toUpperCase(), '<span class="matchedClass">' + unmatchedLine.toUpperCase() + '</span>'));
           return false;
       }
  });
var list=$('.samli span');
$(list.get().reverse())。每个(函数(){
var currentLine=$(this.html();
var unmatched=不匹配线;
if(currentLine.indexOf(不匹配)!=-1){
$(this.html($(this.text().replace(“,”).replace(“&“,”&;”).replace(unmatchdline.toUpperCase(),“”+unmatchdline.toUpperCase()+“”));
返回false;
}
});
HTML的布局如下所示

<ul class="boxSlider">
<li>
    <ul class="sampleAddress">
    <li><span>something</span></li>
    <li><span>something</span></li>
    <li><span>something</span></li>
    </ul>
</li>
<li>
    <ul class="sampleAddress">
    <li><span>something</span></li>
    <li><span>something</span></li>
    <li><span>something</span></li>
    </ul>
</li>
</ul>
    • 某物
    • 某物
    • 某物
    • 某物
    • 某物
    • 某物

ul使用单独的循环

$('.sampleAddress').each(function () {
    var list = $(this).find('li span');
    $(list.get().reverse()).each(function () {
        var currentLine = $(this).html();
        var unmatched = unmatchedLine;
        if (currentLine.indexOf(unmatched) !== -1) {
            $(this).html($(this).text().replace("  ", " ").replace("&", "&AMP;").replace(unmatchedLine.toUpperCase(), '<span class="matchedClass">' + unmatchedLine.toUpperCase() + '</span>'));
            return false;
        }
    });
})
$('.samdesirect')。每个(函数(){
var list=$(this.find('li span');
$(list.get().reverse())。每个(函数(){
var currentLine=$(this.html();
var unmatched=不匹配线;
if(currentLine.indexOf(不匹配)!=-1){
$(this.html($(this.text().replace(“,”).replace(“&“,”&;”).replace(unmatchdline.toUpperCase(),“”+unmatchdline.toUpperCase()+“”));
返回false;
}
});
})

这个循环到底在做什么?你在找什么?