我有這個按鈕,誰有一個圖標(圖片)。現在,我想要做的就是點擊一個按鈕圖標(圖片)會變成另一個圖標,當您再次點擊它時會跳回到舊圖標上。 (如切換原理)。如何更改點擊按鈕圖標?
這裏是我的按鈕的CSS代碼:
.w8-button {
display: table;
padding: 7px 15px 8px 15px;
border: none;
font-family: "open_sans_lightregular";
font-size: 13px;
font-weight: bold;
cursor: pointer;
opacity: 0.9;
}
這裏是CSS圖標代碼:
.w8-button.iconize {
padding-right: 50px !important;
background: url(D:/firstPicture.png) no-repeat 115px center;
}
這是我怎麼稱呼我的HTML按鈕:
<li>
<input type="submit" id="w8-d-blue" name="w8-d-blue" class="w8-button iconize" value="Button"/>
</li>
有人可以告訴我如何在JavaScript中執行代碼,當我點擊按鈕時,圖標(背景圖片)將會改變並保持那樣,un直到你再次點擊將回到舊的(如切換系統)
你願意使用jQuery?它的'.toggleClass()'函數非常適合這個。 – Barmar
在您努力編寫問題之前,我建議您尋找解決此問題的現有答案。像http://stackoverflow.com/questions/195951/change-an-elements-css-class-with-javascript&http://stackoverflow.com/questions/11006406/jquery-toggle-css-class這樣的答案詳情。 – Swordfish0321