是的,有更好的方法:
将 onClick 事件侦听器添加到 svg,然后使用
event.target
<script> function onSvg(event) { on(event.target.id); } </script> <svg onClick="onSvg" ></svg>