您可以使用 document.write 在跨度内绘制一个 svg 路径吗?svg 的工作不需要 span,它只是确保 svg 与 carat 旁边的任何文本保持内联。我使用 margin-bottom 将其与文本垂直居中,但可能还有另一种方法可以做到这一点。这就是我在博客侧导航(减去 js)上所做的。如果旁边没有文本,则不需要跨度或边距底部偏移。
<div id="ID"></div>
<script type="text/javascript">
var x = document.getElementById('ID');
// your "margin-bottom" is the negative of 1/2 of the font size (in this example the font size is 16px)
// change the "stroke=" to whatever color your font is too
x.innerHTML = document.write = '<span><svg style="margin-bottom: -8px; height: 30px; width: 25px;" viewBox="0,0,100,50"><path fill="transparent" stroke-width="4" stroke="black" d="M20 10 L50 40 L80 10"/></svg></span>';
</script>