Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/425.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 如何将复选框选中的字符串值与li元素进行比较以编辑最后一个_Javascript_Php_Html_Jquery_Web - Fatal编程技术网

Javascript 如何将复选框选中的字符串值与li元素进行比较以编辑最后一个

Javascript 如何将复选框选中的字符串值与li元素进行比较以编辑最后一个,javascript,php,html,jquery,web,Javascript,Php,Html,Jquery,Web,如何将复选框选中的字符串值与li元素进行比较,以编辑最后一个元素。 比如说 jQuery(function($){ // start ajax $('#filter input[type="checkbox"]').on('change', function(){ var filter = $('#filter'); /* Stuff to do every *odd* time the elem

如何将复选框选中的字符串值与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');
});
    // load more toggle end


    $('#filter input[type="checkbox"]').click(function () {
            $(this).siblings('span').toggleClass('active');
        });
    // end of stack
    });
// end of stack


Усиление иммунитета

只需将其添加到您的
success
函数,而不是
$(“.usage product list li”)。每个(函数(){})

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');
       }
    });
});

只需将它添加到您的
success
函数中,而不是
$(“.usage product list li”)。每个(函数(){})

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');
       }
    });
});
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');
       }
    });
});