所以我在我的網站上有一個圖像是一個圖像,我試圖做到這一點,當你點擊按鈕的圖像時,它會變成一個不同的按鈕的圖像給它按下按鈕的效果。在互聯網上四處尋找後,這就是我想出了:點擊圖像變化
<p style="text-align: center;">
<span style="font-family: arial, helvetica, sans-serif;">
<a href="/index.php/about-us/about-cmi">
<img alt="" onclick="this.src='/images/yootheme/Button_Template_Long_CMI_Click copy.png';" src="/images/yootheme/Button_Template_Long_CMI copy.png" style="width: 144px; height: 35px;" />
</a>
</span>
</p>
我有這個原本:
<p style="text-align: center;">
<span style="font-family: arial, helvetica, sans-serif;">
<a href="/index.php/about-us/about-cmi">
<img alt="" src="/images/yootheme/Button_Template_Long_CMI copy.png" onclick="this.src='/images/yootheme/Button_Template_Long_CMI_Click copy.png';" style="width: 144px; height: 35px;" />
</a>
</span>
</p>
但是,當我救了它,它切換原始出處和onclick
源。我的問題是,當我點擊按鈕圖像時,圖像確實發生了變化,但無論出於何種原因,出現的圖像都是破碎的圖像,而且我的圖像路徑都是正確的,因爲當我將它輸入到我的瀏覽器,它會轉到正確的圖像。
我會使用onmousedown事件的onmouseup – mplungjan
這可以用CSS來實現:我甚至不會使用Javascript或img標籤來實現這樣的事情(除非標記是你控制範圍之外的東西)。這可能有所幫助:http://www.usabilitypost.com/2008/12/16/pressed-button-state-with-css/ – technophobia
@mplungjan這工作完美!非常感謝! – MoneyMike