使用jQuery从CSS文件获取属性
我有一个CSS文件。在其中的某个地方,我有一个:
.color-base {color:#f0f0f0; }
我的问题是:是否可以直接在jQuery脚本上调用.Color-Base来动态设置关联的颜色?
I have a css file. Somewhere in it I have this:
.color-base { color: #f0f0f0; }
My question is: is it possible to call .color-base directly on a jQuery script to dynamically set the associated color?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,您可以通过jQuery动态设置样式。
Yes, you can dynamically set styles via jQuery.
如果您询问是否可以更新CSS文件,则答案是否。但是,您已经在CSS文件中声明了一个类,并且需要分配给HTML中的某些元素,然后可以使用jQuery更改该元素的颜色,而CSS文件保持不变。像这样,CSS颜色变化部分就像@kenny正确指出的那样:
If you are asking if you can update the CSS file, the answer is NO. However, you have declared a class in the css file and you need to assign to some element in your HTML and then you can change the color of that element using jQuery, while your CSS file remains unchanged. Like this, css color change part is like rightly pointed out by @Kenny: