亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何將復選框選中的字符串值與 li 元素進行比較以編輯最后一個

如何將復選框選中的字符串值與 li 元素進行比較以編輯最后一個

PHP
哆啦的時光機 2023-04-21 16:38:35
如何將復選框選中的字符串值與 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');

       }

    });

});


查看完整回答
反對 回復 2023-04-21
  • 1 回答
  • 0 關注
  • 122 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號