我想你想要的是这样的:
var d;
if (c("body").find("#lightbox-buttons").length < 1) {
this.list = c(a.template || this.template).addClass(a.position || "top").prependTo(g.utility.find("> div"));
d = {
prev: this.list.find(".btnPrev").click(g.prev),
next: this.list.find(".btnNext").click(g.next),
play_fast: this.list.find(".btnFast").click(g.play_fast).addClass(g.player_fast.isActive ? "btnPlayOn" : "")
};
//this assumes that the buttons you need to remove the class from all have the same class, in this example 'btnToRemoveClassFrom'
this.list.find('.btnToRemoveClassFrom').removeClass('classToRemove');
}
或者,如果您需要从中删除类的按钮不在列表中,则最后一行很简单:
c('.btnToRemoveClassFrom').removeClass('classToRemove');
btnPlayOn
如注释中所述,要首先检查类的存在,请使用:
if (this.list.find('.btnPlayOn').length > 0) {
c('.btnToRemoveClassFrom').removeClass('classToRemove');
}
顺便说一句,为什么在地球上c
被用作 jQuery 的速记变量?在很多情况下,把它做成一些其他的东西是有意义的,$
但至少是挑选$j
或一些远程有意义的东西。
编辑:我认为这个版本更具可读性:
var d;
if (c("body").find("#lightbox-buttons").length < 1) {
this.list = c(a.template || this.template).addClass(a.position || "top").prependTo(g.utility.find("> div"));
var btnFast = this.list.find(".btnFast");
d = {
prev: this.list.find(".btnPrev").click(g.prev),
next: this.list.find(".btnNext").click(g.next),
play_fast: btnFast.click(g.play_fast)
};
btnFast.addClass(g.player_fast.isActive ? "btnPlayOn" : "");
//this assumes that the buttons you need to remove the class from all have the same class, in this example 'btnToRemoveClassFrom'
if (this.list.find('.btnPlayOn').length > 0) {
this.list.find('.btnToRemoveClassFrom').removeClass('classToRemove');
}
}