以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 SVG/GML/VRML/X3D/XAML 』  (http://bbs.xml.org.cn/list.asp?boardid=21)
----  如何将css样式指令通过javascript代码加入svg  (http://bbs.xml.org.cn/dispbbs.asp?boardid=21&rootid=&id=75300)


--  作者:JonnyBian
--  发布时间:6/8/2009 11:40:00 AM

--  如何将css样式指令通过javascript代码加入svg
如何将css样式指令通过javascript代码加入到svg文件?
如何把svg整个文档转换成字符串?svg文件代码如下:

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href="http://localhost:5431/css/SVGStyle.css" type="text/css"?>
<!-- Generator: Adobe Illustrator 14.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 43363)  -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="图层_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
  width="1024px" height="600px" viewBox="0 0 1024 600" enable-background="new 0 0 1024 600" xml:space="preserve" >
<path fill="none" stroke="#000000" d="M169.397,525.468L169.397,525.468L169.397,525.468z"/>
<circle id="circle32" cx="308.957" cy="146.5" pointer-events="none"  r="43.836" />
<circle id="circle33" cx="455.5" cy="101.5" pointer-events="none" r="37.255"/>
<circle id="circle34" cx="590.637" cy="40" pointer-events="none" r="26.531"/>
<circle id="circle35" cx="731.5" cy="140" pointer-events="none" r="33.375"/>
</svg>

我用以下的方法试过,但是不好使,图片还是不能正常显示

    var root = SvgMainMapDoc.documentElement;
    var newItem = SvgMainMapDoc.createProcessingInstruction("xml-stylesheet","href='SVGStyle.css' type='text/css'");

    SvgMainMapDoc.insertBefore(newItem,root);


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
31.250ms