0

要素でトグル クラスを操作しようとしていますが、スクリプトが他の関数を実行しており、クラス名で処理されているため、toggleClass 機能を使用できません。したがって、removeClass / addClass を使用しています。何らかの理由で、私はそれを機能させることができません。以下のスクリプトを見つけてください。

$(".view-followers").click(function(){
    alert("off");
    $(this).removeClass("view-followers");
    $(this).addClass("view-followers-on");

});

$(".view-followers-on").click(function(){
    alert("on");
    $(this).removeClass("view-followers-on");
    $(this).addClass("view-followers");
});

または、jsFiddle で表示できます。 http://jsfiddle.net/dannyj6/UGBda/

ご協力いただきありがとうございます。

4

6 に答える 6

0

代替を呼び出すtoogleClass()関数を使用します

$(".view-followers, .view-followers-on").click(function(){
    $(this).toggleClass("view-followers view-followers-on");
})

;

于 2013-09-09T11:32:16.047 に答える