【发布时间】:2014-07-23 20:18:59
【问题描述】:
我尝试向 SVG 元素添加样式表,如下所示:
var theSvg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
var theStyle = document.createElementNS("http://www.w3.org/2000/svg", "style");
theSvg.appendChild(theStyle);
console.log("theStyle.sheet=", theStyle.sheet); // undefined, try adding svg to DOM
document.body.appendChild(theSvg);
console.log("theStyle.sheet=", theStyle.sheet); // still undefined
我应该怎么做才能到达theStyle 中的工作表节点?
这里有一个小提琴:http://jsfiddle.net/XaV7D/2/
【问题讨论】:
-
通过lists.w3.org/Archives/Public/www-svg 联系 w3c svg 工作组并要求他们将其添加到 SVG 2 规范中。
-
谢谢,@RobertLongson。完成。
-
这导致了规范编辑操作:w3.org/Graphics/SVG/WG/track/actions/3277。我刚刚推送了将 LinkStyle(又名工作表访问器)添加到 SVGStyleElement 的更新。要在 Blink (Opera/Chrome) 中跟踪此实现,请参阅 crbug.com/399271。
-
@ErikDahlström 很高兴看到很多人在合作!
标签: javascript dom svg stylesheet