我試圖讓我的小傳送帶控件的每個標題/塊欄在「活動」並顯示其內容時變爲藍色。現在他們會在點擊時保持藍色和黑色之間的切換,這幾乎只是測試的東西,但總體來說有人可能會修改我的JavaScript來控制每個按鈕的活動/非活動狀態來做到這一點。只在需要時將div更改爲活動類
我已經離開現場的URL來看看,所以你可以看到,有些代碼:
直播網址:(首頁,旁邊的大圖)http://bit.ly/1bijza0
HTML
<ul id="index-controls">
<li><div id="1" class="active">FREE DISC Profile</div>
<ul>
<li><h2>Training that fits like a glove</h2></li>
<li><p>Your company is as individual as the people it employs; and as such, it’s likely that your training requirements don’t tick any one, particular box. You may currently have a personnel issue that requires urgent attention. Or, you are taking a serious look at the management strategies you use to run your organisation and are considering an overhaul.</p></li>
</ul>
</li>
<li><div id="2">Last Minute Availability</div>
<ul>
<li><h2>Training that fits like a glove</h2></li>
<li><p>Your company is as individual as the people it employs; and as such, it’s likely that your training requirements don’t tick any one, particular box. You may currently have a personnel issue that requires urgent attention. Or, you are taking a serious look at the management strategies you use to run your organisation and are considering an overhaul.</p></li>
</ul>
</li>
<li><div id="3">Bespoke Training</div>
<ul>
<li><h2>Training that fits like a glove</h2></li>
<li><p>Your company is as individual as the people it employs; and as such, it’s likely that your training requirements don’t tick any one, particular box. You may currently have a personnel issue that requires urgent attention. Or, you are taking a serious look at the management strategies you use to run your organisation and are considering an overhaul.</p></li>
</ul>
</li>
</ul>
的JavaScript
jQuery('#1').click(function() {
jQuery(this).toggleClass('active');
});
jQuery('#2').click(function() {
jQuery(this).toggleClass('active');
});
jQuery('#3').click(function() {
jQuery(this).toggleClass('active');
});
CSS
#index-controls div { display: block; background-color: #222424; font-weight: bold; margin: 0px; cursor: pointer; padding: 19px 20px 20px 20px; border-bottom: 1px solid #4e92ad; color: #fff; font-size: 1.1em; }
#index-controls .active { background-color: #4e92ad; }
#index-controls ul { padding-left: 0; margin-top: 0; }
#index-controls ul{ display: none; background-color: transparent; padding: 10px 10px 0px 10px; }
#index-controls ul li { list-style-type: none; background-color: transparent; width: 240px; color: #fff; font-size: 12px; }
採取bbf的內容,你可以使用:active {c olor:red} –
我認爲toggleClass在最後一個jQuery中已棄用 –
@JonasGrumann在文檔頁面上沒有提及棄用:http://api.jquery.com/toggleClass/ – gpgekko