如何在 SVG 中操作样式标记



我想使用 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面规则并用其他东西代替它。谁能告诉我它是怎么做到的?

我尝试添加以下内容:

<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());

它正在工作..

最新更新