svg param.js的大bug

在svg文件里定义控件,带参数,然后引用。

如果是 text 且没有为其它添加默认值,那么会报错。

即,

<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewbox="0,0,200,200">
<g>
<circle r="100" cx="100" cy="100" style="fill:blue"/>
<text x="50%" y="50%" alignment-baseline="middle" text-anchor="middle" content-value="param(key)"/>
</g>
<script type="text/javascript" xlink:href="lib/param.js" />
</svg>

调用这个文件时会报错。原因就是text 没有赋默认值。

修改 param.js 的148行为:

if (el.firstChild){
el.replaceChild( document.createTextNode( newVal ), el.firstChild );
}else{
el.appendChild(document.createTextNode(newVal));
}

 

即可

posted @ 2017-11-07 10:41  (大贤者模式)  阅读(184)  评论(0编辑  收藏  举报