svg param.js的大bug

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

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

即,app

<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 没有赋默认值。svg

修改 param.js 的148行为:xml

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

 

便可ip

相关文章
相关标签/搜索