我有幾個樣式需要用JS去改變,因為還需要改變CSS偽類的樣式,所以我得用JS創建style插入標簽里面,然后在style里面寫入要改變的樣式,可是style里面的樣式不能使用變量,而我現在的問題是樣式的值必須使用變量?代碼如下:$('html').append("<style>.className:after{background:red;border-color:green}</style>");現在樣式的值只能直接寫,而我想要樣式的值可以使用變量,比如:var bgColor = red, borderColor = green;$('html').append("<style>.tanmu-contain-171208 .tanmu-content-171208{.className:after{background:bgColor;border-color:borderColor}</style>");能實現嗎?還有其他的方法實現嗎
JS創建的style樣式怎么使用變量?
慕少森
2019-02-14 17:15:19
