I have a page which has <link>
in the header that loads the CSS named light.css
. I also have a file named dark.css
. I want a button to swap the style of the page all together (there are 40 selectors used in css file and some do not match in two files).
我如何用JS删除对light.css
的引用,删除所有应用的样式,然后加载dark.css
并应用其中的所有样式?我不能简单地重置所有元素,因为有些样式是通过不同的css文件应用的,有些是由JS动态生成的.有没有一种简单而有效的方法可以在不重新加载页面的情况下实现这一点?Vanilla JS更可取,不过我会在以后的处理中使用jQuery,所以jQ也可以.