我建议将 display 属性设置为 none 而不是添加和删除节点。
或者,如果您有离散数量的权重,您可以使用 CSS 来完成,如下所示:
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
<style type="text/css">
<!-- Hide all links with weights that we don't want -->
.weight0,.weight2,.weight4,.weight6 {display:none}
</style>
<a xlink:href="#" class="weight0">
<text y="20">weight 0</text>
</a>
<a xlink:href="#" class="weight2">
<text y="40">weight .2</text>
</a>
<a xlink:href="#" class="weight4">
<text y="60">weight .4</text>
</a>
<a xlink:href="#" class="weight6">
<text y="80">weight .6</text>
</a>
<a xlink:href="#" class="weight8">
<text y="100">weight .8</text>
</a>
<a xlink:href="#" class="weight10">
<text y="120">weight 1</text>
</a>
</svg>