我有一个类似的问题 本栈职位但是,想在jquery链中调用该函数。这是我的伪代码。
function togglePanels(f) {
var customchain;
if (f == 'n') {
customchain = $.next();
} else {
customchain = $.prev();
}
let $next_or_prev_panel = $current_panel
.parents("div")
.eq("2")
.customchain("div")
.find(".panel");
}
我猜想解决方案会涉及到jQuery库的原型设计?
一个解决方案是使用条件(三元)操作符与一个字符串来设置。customchain
喜欢。
customchain = f == 'n' ? 'next' : 'prev';
然后动态地使用它,像:
let $next_or_prev_panel = $current_panel
.parents("div")
.eq("2")[customchain]("div")
.find(".panel");