如何在SVG中操作样式标记

时间:2015-01-07 14:09:58

标签: javascript css stylesheet

我想使用Javascript从样式标记中删除一些规则。 例如:

<style>

    @font-face { font-family:&quot;Arial&quot;;src:url(&quot;#FontID1&quot;) format(svg)}
    @font-face { font-family:&quot;Nyala&quot;;src:url(&quot;#FontID0&quot;) format(svg)}
    .fil2 {fill:#05BAE4}
    .fil3 {fill:#373435}
    .fil1 {fill:#05BAE4;fill-rule:nonzero}
    .fil0 {fill:#11D6CC;fill-rule:nonzero}
    .fnt1 {font-weight:normal;font-size:189.311;font-family:'Arial'}
    .fnt0 {font-weight:normal;font-size:615.094;font-family:'Nyala'}

  </style>

我想删除@ font-face规则并将其替换为其他内容。 谁能告诉我它是如何完成的?

1 个答案:

答案 0 :(得分:0)

我尝试添加这个:

<script type="text/plain" id="allFonts">
<style type="text/css">
    @font-face {
        font-family: MuseoSlab;
        src: url('/fonts/Museo_Slab.otf');
    }
    @font-face {
        font-family: MuseoSans;
        src: url('/fonts/MuseoSans.otf');
    }
    @font-face {
        font-family: Neuton;
        src: url('/fonts/Neuton.otf');
    }
    @font-face {
        font-family: Stag-Medium;
        src: url('/fonts/STAG-MEDIUM_0.otf');
    }
    @font-face {
        font-family: STAGSANS;
        src: url('/fonts/STAGSANS-MEDIUM_0.otf');
    }
    @font-face {
        font-family: Zapf;
        src: url('/fonts/Zapf.otf');
    }

    @font-face {
        font-family: GLSNECB;
        src: url('/fonts/GLSNECB.otf');
    }

    @font-face {
        font-family: HELVETIA;
        src: url('/fonts/HELVETIA.otf');
    }

    @font-face {
        font-family: "CG Omega";
        src: url('/fonts/STAG-MEDIUM_0.otf');
    }

    @font-face {
        font-family: "Eurostile LT Bold";
        src: url('/fonts/STAGSANS-MEDIUM_0.otf');
    }
</style>
</script>

并在剧本中:

            $("style").after($("#allFonts").text());

它正在运作..