-2
jq(".1st").click(
  function() {   
      jq(this).next("div").slideToggle("normal");
      jq(this).toggleClass(this).attr("id","standfeat2");
  }
);

ドロップボタンをクリックするとメッセージがドロップダウンし、もう一度クリックすると元のクラス「standfeat」に戻ります。私はすべてを試したことを誓います。2 つの CSS ID を切り替えています。1 つは + で、もう 1 つは - です。事前にすべての助けをありがとう!

これは私のCSSです:

#standfeat {
    color:#185596; 
    font-size:24px; 
    padding-left:40px; 
    background: url(../images/standfeat.png) no-repeat 4px 50%; 
    line-height:24px; 
    cursor:pointer; 
    margin:30px 0px; 
} 

#standfeat2 { 
    color:#185596; 
    font-size:24px; 
    padding-left:40px; 
    background: url(../images/standfeat2.png) no-repeat 4px 50%; 
    line-height:24px; 
    cursor:pointer; 
    margin:30px 0px; 
} ​
4

3 に答える 3

1

IDではなくクラスを意味していると思います。toggleClass2つのクラスを切り替えず、クラスf.exを追加または削除します。

jq(this).toggleClass('open');

この関数が最初に呼び出されると、クラスが追加されますopen。次回それを削除するときなど。CSSでそのロジックを使用して、さまざまな状態のスタイルを設定できます。f.ex:

li{ background: url('plus.png') no-repeat; }
li.open{ background-image: url('minus.png'); }

本当にIDを切り替えたい場合は、次のようにすることができます。

this.id = this.id == 'standfeat' ? 'standfeat2' : 'standfeat';
于 2012-08-27T14:40:44.807 に答える
1

クリック時に要素 ID を変更することはおそらく良い考えではありません。その目的のためにクラスを使用する方がはるかにクリーンです (メソッドはあるがtoggleClassメソッドがないのはそのためtoggleIdです)。

css を次のように変更します。

.standfeat { color:#185596; font-size:24px; padding-left:40px; background: url(../images/standfeat.png) no-repeat 4px 50%; line-height:24px; cursor:pointer; margin:30px 0px; }
.standfeat2 { color:#185596; font-size:24px; padding-left:40px; background: url(../images/standfeat2.png) no-repeat 4px 50%; line-height:24px; cursor:pointer; margin:30px 0px; } 

そして、次のjsLを使用できます

jq(".1st").click(
    function() {   
        jq(this).next("div").slideToggle("normal");
        jq(this).toggleClass("standfeat standfeat2");
    }
);

実際のデモ (画像は含まれません)

于 2012-08-27T14:46:28.830 に答える
0

toggleClass()への参照ではなく、クラス名を に渡す必要がありobjectます。

jq(".1st").click(
  function() {   
      jq(this).next("div").slideToggle("normal");
      jq(this).toggleClass("someClassName").attr("id","standfeat2");
  }
);
于 2012-08-27T14:38:43.263 に答える