gpt4 book ai didi

javascript - jQuery - $(this) + 选择器 - .each()

转载 作者:行者123 更新时间:2023-11-28 14:18:06 26 4
gpt4 key购买 nike

我正在尝试执行嵌套的 .each() ,以便我仅定位父级当前迭代的后代。

例如:

$('.row-day').each(function() {
let dayFlag = false;

$(this)('.row-timeslot').each(function() {

});
});

除了我知道上面的方法行不通,但应该可以用来描述我想做的事情。 .row-timeslot 会有很多子项,因此我需要使用 .each。我可能读过 .find() 但我不知道这是否会迭代所有的子项。感谢您的帮助!

最佳答案

$(this)('.row-timeslot') 是无效的 JS 构造。

.row-timeslot.row-day 的子级中,您正在寻找 .find()

$('.row-day').each(function() {
let dayFlag = false;

// here $(this) contains one of .row-days

$(this).find('.row-timeslot').each(function() {
// here $(this) contains one of .row-timeslots
});
});

关于javascript - jQuery - $(this) + 选择器 - .each(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56570817/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com