var svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
svg.innerHTML = '<path id= "3" d=" M 70.7107 40.8248 L -1.42109e-014 -7.10543e-015 " /> <path id= "4" d=" M 70.7107 -40.8248 L 70.7107 40.8248 " />';
document.body.appendChild(svg); //replace document.body with wherever you want to put your svg
通过https://developer.mozilla.org/en-US/docs/Web/API/Node.appendChild
或者更简单:
<html>
<body>
<div id="svgDiv"></div>
<script>
var div = document.getElementById("svgDiv");
var paths = '<path id= "3" d=" M 70.7107 40.8248 L -1.42109e-014 -7.10543e-015 " /> <path id= "4" d=" M 70.7107 -40.8248 L 70.7107 40.8248 " />';
div.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" version="1.1">' + paths + '</svg>';
</script>
</body>
</html>
或者,您可能还想考虑使用jQuery来简化 DOM 操作。