我有一個使用點擊和jquery的褪色一個按鈕被點擊時,顯示一個div,然後改變按鈕的狀態下面....更改個人按鈕狀態
HTML
<a class="link" href="#" data-rel="content1"><img src="http://i.imgur.com/vi1KLp9.png"></a>
<a class="link" href="#" data-rel="content2"><img src="http://i.imgur.com/u1SbuRE.png"></a>
<a class="link" href="#" data-rel="content3"><img src="http://i.imgur.com/u1SbuRE.png"></a>
<a class="link" href="#" data-rel="content4"><img src="http://i.imgur.com/u1SbuRE.png"></a>
<a class="link" href="#" data-rel="content5"><img src="http://i.imgur.com/u1SbuRE.png"></a>
<div class="content-container">
<div id="content1">This is the test content for part 1</div>
<div id="content2">This is the test content for part 2</div>
<div id="content3">This is the test content for part 3</div>
<div id="content4">This is the test content for part 4</div>
<div id="content5">This is the test content for part 5</div>
</div>
CSS
.content-container {
position: relative;
width: 400px;
height: 400px;
}
.content-container div {
display: none;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
JQUERY
$(".link").click(function(e) {
e.preventDefault();
$('.content-container div').fadeOut('slow');
$('#' + $(this).data('rel')).fadeIn('slow');
$(".link img").attr("src", "http://i.imgur.com/u1SbuRE.png");
$(this).find("img").attr("src", "http://i.imgur.com/vi1KLp9.png");
});
$(document).ready(function() {
$(".link")[0].click();
});
這一切工作很大,但我試圖做的是有不同的按鈕/按鍵按下每個五個按鈕的圖像。誰能幫忙?
我曾經這樣做過,而不是這樣做。你有一個例子或鏈接到一個,所以我可以讀? – fightstarr20
我添加了一個工作小提琴 –