You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SVG打开报错:path属性d期望M/m开头moveto命令,如何解决?

报错根因

错误由第一个<path>标签的d属性不符合SVG路径规范直接导致:

  • SVG的路径指令必须以移动指令M(绝对坐标)或m(相对坐标)开头,作用是定义路径绘制的起始位置,你第一个path的d属性直接写了375,23.5c...,没有添加开头的M指令,所以解析器直接抛出了找不到moveto命令的错误。
  • 额外发现隐藏问题:最后一个<tspan>标签的x属性为空值,会导致部分渲染器报警告或渲染异常,建议补充对应的x坐标值。

修复后完整代码

<svg version="1.1" 
    xmlns="http://www.w3.org/2000/svg" 
    xmlns:xlink="http://www.w3.org/1999/xlink" 
    x="0px" 
    y="0px"
    viewBox="0 0 400 30" 
    style="enable-background:new 0 0 400 30" 
    xml:space="preserve">
<g stroke="#fff" fill="none">
          <!-- 路径开头补充大写M指令 -->
          <path d="M375,23.5c-3,0-5.8-3.8-5.8-8.5s2.5-8.5,5.8-8.5c3,0,5.8,3.8,5.8,8.5C
               381,19.7,
               378,23.5,
               375,23.5"/>
          <path d="M35,23.5c-3,0-5.8-3.8-5.8-8.5s2.5-8.5,5.8-8.5"/>
          <path d="M34.8,6.5h
               340"/>
          <path d="M34.8,23.5h
               340"/>
        </g>
        <g font-size="12px">
          <text text-anchor="end">
            <tspan y="19" x="27">X</tspan>
            
          </text>
          <text text-anchor="start">
            <tspan y="19" x="383">B</tspan>
            
          </text>
          <text text-anchor="middle">
            <!-- 补充中间位置x坐标,可根据实际需求调整数值 -->
            <tspan y="19" x="200">23424</tspan>
            
          </text>
        </g>
</svg>

内容的提问来源于stack exchange,提问作者Samuel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.24 12:24:06