据我所知,没有jQuery的方法可以做到这一点。可能有一些jQuery插件,但我不知道。
基本上,您可以使用对象的
styleSheets属性来解决第一个问题
document。这比需要走到相当深的对象链要复杂得多,但是尽管如此,它仍可在包括Internet
Explorer 6在内的所有主要浏览器中使用。以下是概念证明。CSS位于STYLE标记内,但也可以与外部CSS一起使用。我让你做抽象。
概念证明
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head><title></title><meta http-equiv="content-type" content="text/html; charset=UTF-8"><meta http-equiv="imagetoolbar" content="false"><meta http-equiv="imagetoolbar" content="no"><style type="text/css">.classname { color: red; font-size: 14px;}</style><script type="text/javascript">window.onload = function() { document.getElementById("button").onclick = function() { var ss = document.styleSheets; for (var i=0; i<ss.length; i++) { var rules = ss[i].cssRules || ss[i].rules; for (var j=0; j<rules.length; j++) { if (rules[j].selectorText === ".classname") { rules[j].style.color = "green"; } } } };}</script></head><body><h1 >Some red text</h1><button id="button">Make text green</button></body></html>对于您的第二个问题,我没有时间编写解决方案,但是它涉及到如上所述读取CSS声明并使用
cssTextCssRule对象的属性来构建字符串,该字符串最终将使用来发送到服务器。
Ajax POST请求。服务器端是您的事。
希望能帮助到你



