从 Javascript 更改 CSS 规则集 [英] Changing a CSS rule-set from Javascript

查看:32
本文介绍了从 Javascript 更改 CSS 规则集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以动态更改 CSS 规则集(即某些 JS 会在用户单击小部件时更改 CSS 规则集)

Is it possible to make changes to a CSS rule-set dynamically (i.e. some JS which would change a CSS rule-set when the user clicks a widget)

这个特定的 CSS 规则集应用于页面上的许多元素(通过类选择器),我想在用户单击小部件时修改它,以便所有具有 class改变.

This particular CSS rule-set is applied to lots of elements (via a class selector) on the page and I want to modify it when the user clicks the widget, so that all the elements having the class change.

推荐答案

可以,但是比较麻烦.关于如何做到这一点的最佳参考是以下文章:Totally Pwn CSS with Javascript (网络存档链接).

You can, but it's rather cumbersome. The best reference on how to do it is the following article: Totally Pwn CSS with Javascript (web archive link).

我设法让它与 Firefox 和 IE 一起使用 - 我不能在 Chrome 中使用它,尽管它似乎支持 DOM 方法.ricosrealm 报告说它也适用于 Chrome.

I managed to get it to work with Firefox and IE - I couldn't in Chrome, though it appears that it supports the DOM methods.ricosrealm reports that it works in Chrome, too.

这篇关于从 Javascript 更改 CSS 规则集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆