如何將復選框選中的字符串值與 li 元素進行比較以編輯最后一個。例如。 jQuery(function($){// start ajax $('#filter input[type="checkbox"]').on('change', function(){ var filter = $('#filter'); /* Stuff to do every *odd* time the element is clicked */ $.ajax({ url:filter.attr('action'), data:filter.serialize(), // form data type:filter.attr('method'), // POST beforeSend:function(xhr){ filter.find('button').css('opacity', '1').text('Загрузка...'); // changing the button label }, success:function(data){ filter.find('button').css('opacity', '0');; // changing the button label back if($(".checkbox:checked").length == 0) { $('#response').empty(); } else { $('#response').html(data); }; $(".usage-product-list li").each(function () { if ($(this).text() == 'Усиление иммунитета') { $(this).css('color', 'red'); } }); } }); return false; });//end jquery ajax // load more toggle start $('.load-more').toggle(function() { $(this).html('Меньше параметров <i class="fas fa-angle-up"></i>'); $('.row-wrap').slideDown('slow');}, function() { $(this).html('Больше параметров <i class="fas fa-angle-down"></i>'); $('.row-wrap').slideUp('slow');});在我的代碼中,如果 li 包含我放入字符串中的文本,我必須更改 li 的顏色,但是如何使用等于每個選中的復選框父 LABEL 字符串值的文本字符串更改每個 li 顏色?
1 回答

catspeake
TA貢獻1111條經驗 獲得超0個贊
只需將此添加到您的success函數而不是$(".usage-product-list li").each(function () {});:
let checked = $("input[type='checkbox']:checked")
checked.each(function() {
let labelText = $(this).closest("label").text();
$(".usage-product-list li").each(function() {
if ($(this).text() == labelText) {
$(this).css('color', 'red');
}
});
});
- 1 回答
- 0 關注
- 122 瀏覽
添加回答
舉報
0/150
提交
取消