Jquery 将每个块的日期值作为类添加
您好,我想获取每个日期值作为字符串,并将其作为类添加到文章$('.alle feesten'),它现在所做的是将所有值添加到每个块,以便每个块获得3个额外的类。每个块只应获取其日期,以便块1获取值1。。。提前谢谢Jquery 将每个块的日期值作为类添加,jquery,each,Jquery,Each,您好,我想获取每个日期值作为字符串,并将其作为类添加到文章$('.alle feesten'),它现在所做的是将所有值添加到每个块,以便每个块获得3个额外的类。每个块只应获取其日期,以便块1获取值1。。。提前谢谢 $('.alle-feesten').each(function(i) { $(this).addClass(zonderSlash($('.feest-datum').text())); }); function zonderSlash(datum) {
$('.alle-feesten').each(function(i) {
$(this).addClass(zonderSlash($('.feest-datum').text()));
});
function zonderSlash(datum) {
datum_string = datum.split('/');
new_date = datum_string[0] + datum_string[1] + datum_string[2]
return new_date;
}
假设
.feestdatum
是.alleefeesten
的祖先,您可能希望这样做
$('.alle-feesten').each(function(i) {
var self = $(this);
self.addClass(zonderSlash(self.find('.feest-datum').text()));
});
你是说像这样的事吗
var aux = 0;
$('.alle-feesten').each(function(i) {
$(this).addClass(zonderSlash($('.feest-datum').text()), aux);
aux++;
});
function zonderSlash(datum, i) {
datum_string = datum.split('/');
new_date = datum_string[i];
return new_date;
}
谢谢你的评论:)