下面是我用來顯示點擊內容的代碼(如手風琴)。點擊「a」標籤即可顯示內容。那麼如何將bgcolor添加爲點擊「a」標籤的白色。點擊添加課程
HTML
<ul class="accordion">
<li>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="336" class="name">lorem</td>
<td width="101" class="info current" idcust="tr1" custdata="#cnt1"><a href="#">test</a></td>
<td width="107" class="info" idcust="tr1" custdata="#cnt2"><a href="#">test2</a></td>
<td width="102" class="info" idcust="tr1" custdata="#cnt3"><a href="#">test2</a></td>
<td width="104" class="info" idcust="tr1" custdata="#cnt4"><a href="#">test2</a></td>
<td width="100" class="info" idcust="tr1" custdata="#cnt5"><a href="#">test2</a></td>
<td width="100" class="info" idcust="tr1" custdata="#cnt6"><a href="#">test2</a></td>
</tr>
<tr class="cntetn" customid="tab_content">
<td colspan="7" id="tr1">
<span id="cnt1"><p>content here</p></span>
<span id="cnt2"><p>content here</p></p></span>
<span id="cnt3"><p>content here</p></p></span>
<span id="cnt4"><p>content here</p></p></span>
<span id="cnt5"><p>content here</p></p></span>
<span id="cnt6"><p>content here</p></p></span>
</td>
</tr>
</table>
</li>
</ul>
腳本
$(function(){
$('ul').accordion();
$(".info").find("a").click(function(){
var trid = $(this).parent().attr("idcust");
var trdata = $(this).parent().attr("custdata");
// Hide all content divs and show only the one related to the click
$("#"+trid).children().hide();
$(trdata).show();
$("#"+trid).toggle();
});
});
是個做到這一點是http://stackoverflow.com/questions/11930738/add-class-on-click的副本? – Nope 2012-08-13 08:38:43
這是有效的一個 – Sowmya 2012-08-13 08:41:04
@FrançoisWahl該問題已被刪除。 – irrelephant 2012-08-13 08:41:31