如何动态重新加载 .css?
我有一个网站,我想通过让用户单击加载相应建议样式的链接来呈现不同的样式以进行评估。如何动态重新加载 .css 文件?
I have a website that I would like to present different styles for evaluation by having users click on a link(s) where an according proposed style gets loaded. How can I dynamically reload .css files?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 javascript,您应该能够操作 css 元素(例如
document.createElement("style");
,然后用您需要的内容填充它并将其附加到页面。替换该元素将会改变但是,如果您尝试在链接的 .css 文件之间切换,它可能无法动态工作,因为它可能需要刷新页面。Using javascript you should be able to manipulate the css elements (such as
document.createElement("style");
and then filling it with what you need and appending it to the page. Replacing that element will change the css that the page is styled with. However, if you are trying to switch between linked .css files, it may not work dynamically because it could require a page refresh.这招成功了!
This did the trick!