代碼:選擇風格來回
<style> .demo {color: yellow; background-color: purple} </style>
<p class="demo">my text</p>
<button id="change">click</button>
<script>
window.onload = function() {
var flipColors = query("#change");
var target = query(".demo");
flipColors.onclick = function() {
style(target, "color", "white");
style(target, "background-color", "black");
};
};
</script>
當我點擊按鈕樣式的變化。
我的問題是我需要添加到JS什麼,當按鈕 再次點擊 - 它會恢復原來的風格,如果它再次點擊它將再次激活該功能,而不是做兩個按鈕。
我知道我可以創建.demo
和.demo1
類並切換它們,但我想了解如何使它成爲可能。
注:只需簡單的JS,不是JQuery的等
謝謝你的回答,我知道如何切換(切換)課程,我想學習另一種方式。 –
完美!非常感謝 –