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 に答える