替换.toggle(在jQuery 1.9中
我在jQuery 1.9中找到了不同的切换选项,但在我的案例中无法实现:替换.toggle(在jQuery 1.9中,jquery,click,toggle,Jquery,Click,Toggle,我在jQuery 1.9中找到了不同的切换选项,但在我的案例中无法实现: $('.thumb.flip').toggle( function () { $(this).find('.thumb-wrapper').addClass('flipStop'); }, function () { $(this).find('.thumb-wrapper').removeClass('flipStop flipIt'); } ); 您可以使用“单击”事件,然后使用“:visible”选中(如果元素此时
$('.thumb.flip').toggle(
function () {
$(this).find('.thumb-wrapper').addClass('flipStop');
},
function () {
$(this).find('.thumb-wrapper').removeClass('flipStop flipIt');
}
);
您可以使用“单击”事件,然后使用“:visible”选中(如果元素此时可见):
- 如果元素可见-通过添加类似于代码的类来隐藏它,或者只需:~.hide()
- 如果元素不可见-添加/删除类或使用:~.show()
<div class="thumb flip" data-clicked="0">
$('.thumb.flip').click(function () {
var data = $(this).data('clicked'), $descendant=$(this).find('.thumb-wrapper');
if (data) {
$descendant.removeClass('flipStop flipIt');
} else {
$descendant.addClass('flipStop');
}
data == 0 ? $(this).data('clicked', 1) : $(this).data('clicked', 0);
});
如果您想要相同的代码工作,请查看迁移项目,否则请使用类似于您的代码的替代代码,因为它似乎有逻辑问题,或者缺少某些内容……flipIt的意义是什么?您从未在开始时添加过它,那么它为什么会出现呢?
$('.thumb.flip').click(function () {
if ($(this).find('.thumb-wrapper').hasClass('flipstop')) {
$(this).find('.thumb-wrapper').removeClass('flipStop flipIt');
} else {
$(this).find('.thumb-wrapper').addClass('flipStop');
}
});