Javascript Jquery循环通过每个ul的每个li
目前有一个这样的循环,它遍历每个li,在li中查找某些内容并添加一个类。问题是布局有多个UL,即,我希望它在每个UL中找到li。现在,它在找到任何符合我的IF条件的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
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("&", "&").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("&", "&").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;
}
});
})
这个循环到底在做什么?你在找什么?