我試圖通過設置其屬性cssText修改CSS樣式表,但它沒有堅持。如何使用JavaScript修改CSS樣式表(不是我如何改變元素的樣式表)
推進此按鈕應可以切換從一個紅色箭頭其外觀以黑色箭頭和黑色的,但沒有改變。這出現在JavaScript日誌中:
changed cssText from .movebutton button { width: 100px; height: 100px; background-image: url("redarrow.svg"); } to .movebutton button { width: 100px; height: 100px; background-image: url("redarrow.svg"); } should be .movebutton button { width: 100px; height: 100px; background-image: url("blackarrow.svg"); } changed cssText from .movebutton button { width: 100px; height: 100px; background-image: url("redarrow.svg"); } to .movebutton button { width: 100px; height: 100px; background-image: url("redarrow.svg"); } should be .movebutton button { width: 100px; height: 100px; background-image: url("redarrow.svg"); } changed cssText from .movebutton button { width: 100px; height: 100px; background-image: url("redarrow.svg"); } to .movebutton button { width: 100px; height: 100px; background-image: url("redarrow.svg"); } should be .movebutton button { width: 100px; height: 100px; background-image: url("blackarrow.svg"); } changed cssText from .movebutton button { width: 100px; height: 100px; background-image: url("redarrow.svg"); } to .movebutton button { width: 100px; height: 100px; background-image: url("redarrow.svg"); } should be .movebutton button { width: 100px; height: 100px; background-image: url("redarrow.svg"); }
所以基本上看起來好像這個改變並沒有粘住。這是在Firefox 7.0.1中。 ?
要改變相關元素上的類比重寫樣式表要容易得多。如何爲類設置'.movebutton red'和'.movebutton black'?足夠容易扎那兩個一起在樣式表,然後你只之間切換紅/黑,這是很容易,對重寫樣式表,這是更難。 –
我知道我可以解決此問題通過更改類,我只是想知道爲什麼沒有工作,以供將來參考。 –