Creating an SVG DOM element from a String

前端 未结 4 1890
天命终不由人
天命终不由人 2021-02-05 05:40

How would I go about creating an SVG DOM element from a String?

Example:

var svgStr = \'

        
4条回答
  •  梦如初夏
    2021-02-05 06:37

    Reading and writing the innerHTML of an SVG within HTML seems to work well except in Internet Explorer (9-11): http://cs.sru.edu/~ddailey/svg/IframeSVG.htm . If one needs IE compatibility (as in for a real web app) then use DOM methods to create a suitable container (object, iframe or embed) and build the SVG, one childNode at a time, through DOM methods within that container. ) It's a bit of a chore, but the basics are covered at http://www.w3.org/Graphics/SVG/IG/resources/svgprimer.html#SVG_HTML.

提交回复
热议问题