我有以下jQuery调用链:
$(someSelector).nextUntil(".specialClass").addClass(classBasedSomeSelectorObject)
我需要addClass,它的值是基于someSelector返回的对象。
有没有办法实现它?
答案 0 :(得分:2)
在函数中包装它似乎是最简单的方法,如下所示:
function(selector) {
var class = selector == ".thing" ? "thingClass" : "defaultClass";
$(selector).nextUntil('.specialClass').addClass(class);
}
根据评论更新:
$(selector).each(function() {
var class = "class" + this.id; //whatever logic to get class here
$(this).nextUntil('.specialClass').addClass(class);
});
答案 1 :(得分:1)
$('someSelector').each(function() {
$(this).nextUntil('.specialClass').addClass(/* calculation based on 'this' */);
});