我使用html和非常基本的jQuery的組合來創建一個像按鈕一樣的功能的img,這樣當點擊img時,圖像的src( src1)更改爲另一個src(src2,即按下的按鈕圖像)。 我試圖做到這一點,如果單擊相同的圖像(現在src2),然後它會改回原始的src(src1)。圖像作爲一個按鈕 - 點擊時改變圖像
我希望這不是一個令人頭痛的事情,我可以在需要時澄清。
這裏就是我有下面的代碼:
<!--Html-->
<body>
<img id="pixelbutton" src="images/pixelbutton.png" onClick="pixelbuttonclick()" />
</body>
/* jQuery */
function pixelbuttonclick() {
var pixelbutton = document.getElementById("pixelbutton");
if (pixelbutton.style.src=="images/pixelbutton.png") {
document.getElementById("pixelbutton").src="images/pixelbutton_press.png";
}
else if (pixelbutton.style.src=="images/pixelbutton_press.png") {
document.getElementById("pixelbutton").src="images/pixelbutton.png";
}
}
我是一個巨大的小白,所以不太複雜的答案,如果可能的話,表示讚賞。
這不是jQuery的。 – SLaks
對不起,我還不太清楚JavaScript和jQuery之間的區別。 – user1751775