這個問題完成了第一個問題,我詢問here如何使用jQuery更改點擊圖像。如何用jQuery多次更改圖像的alt屬性?
我忘了說(即使我後來編輯我的帖子),我正在尋找一種方法,每次點擊更改圖像時都有不同的alt屬性。
(這是爲了更好的可及性和SEO優化。)
下面是實際的HTML代碼感謝altCognito:
<img id="radio_btn1" src="originalimage1.jpg" />
<br />
<input type="radio" name="radio_btn1" value='image1.jpg' />
<input type="radio" name="radio_btn1" value='image2.gif' />
<input type="radio" name="radio_btn1" value='image3.png' />
<input type="radio" name="radio_btn1" value='image4.jpeg' />
而jQuery的:
imgFldr = 'images/nameofthesubfolder/';
$("input[type='radio']").click(function() {
$('#'+this.name).attr('src', imgFldr+this.value).attr('alt', 'newattribute');
});
它可以是編輯於jsbin。
@Matt:通常不需要在標題中重複標籤。 – 2010-06-11 13:56:02