<script type="text/ecmascript">
<![CDATA[
function setCoordinates(circle) {
var centerX = Math.round(Math.random() * 1000);
var centerY = Math.round(Math.random() * 1000);
circle.setAttribute("cx",centerX);
circle.setAttribute("cy",centerY);
}
]]>
</script>
<circle class="circles" cx="500" cy="500" r="25" fill="white" filter="url(#f1)" />
<circle class="circles" cx="500" cy="500" r="25" fill="white" filter="url(#f1)" />
<circle class="circles" cx="500" cy="500" r="25" fill="white" filter="url(#f1)" />
<circle class="circles" cx="500" cy="500" r="25" fill="white" filter="url(#f1)" />
<circle class="circles" cx="500" cy="500" r="25" fill="white" filter="url(#f1)" />
<script type="text/ecmascript">
<![CDATA[
setCoordinates(document.getElementsByClassName("circles"));
]]>
</script>
这根本没有效果。但是,当我使用“getElementByID”并为圆圈分配一个 ID 时,它工作正常。(歌剧)