0

我有以下 HTML:

<div id="wrapper">
      <div class="p1">
          <a href="#" class="quickFlipCta"><img src="Test Pictures/QuestionMark.gif" /></a>
      </div>

      <div class="p2">
          <a href="#" class="quickFlipCta"><img src="Test Pictures/flower.gif" /></a>
      </div>
</div>

除了其他一些事情,我希望在特定条件后删除类“quickFlipCta”。这是我的代码片段:

if ( $(this).attr('id') != last.attr('id') ) {
  var that = this;
  var that2 = last;
  setTimeout(function(){
     $(that).parent().parent().quickFlipper({refresh :1}); 
     $(that2).parent().parent().quickFlipper({refresh :1}); 
  }, 1500);
  $('a').removeClass('quickFlipCta');
}

第一条语句完美运行:

    setTimeout(function(){
        $(that).parent().parent().quickFlipper({refresh :1});
        $(that2).parent().parent().quickFlipper({refresh :1});
    }, 1500);

但是$('a').removeClass('quickFlipCta');不起作用。我认为它有问题,但我在 if 语句之外尝试了它并且它有效。知道是什么原因造成的吗?提前致谢。

4

1 回答 1

1

变量last只有值null$(this)

$('a').click(function() {
    if (last) {
        // ...
        // if this if is executed that means last = $(this), 
        // so the condition returns false
        if ($(this).attr('id') != last.attr('id')) {
            // this code is never executed
            $('a').removeClass('quickFlipCta');
        }
        // ...
        last = null;
    } else {
        last = $(this);
    }
});
于 2012-07-18T18:21:11.357 回答