[英]JavaScript how to take target value from one function and multiply by element value for which the checkbox has been checked
[英]how to compare checkbox checked string value with li element to edit last one
如何將復選框選中的字符串值與 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
在我的代碼中,如果 li 包含我放入字符串中的文本,我必須更改它的顏色,但是如何使用文本字符串更改每個 li 顏色等於每個選中的復選框父 LABEL 字符串值?
$(".usage-product-list li").each(function () {
if ($(this).text() == 'Усиление иммунитета') {
$(this).css('color', 'red');
}
});
<label><span></span><input class="checkbox" type="checkbox" name="usage_uluchpoedaemost"/>Улучшение поедаемости</label>
<label><span></span><input class="checkbox" type="checkbox" name="usage_usilimmun"/>Усиление иммунитета</label>
只需將此添加到您的success
function 而不是$(".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');
}
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.