0
下面的代碼應該生成100個隨機矩形。但它不工作。任何人都可以告訴我我做錯了什麼?JavaScripts不支持SVG
<html>
<head>
<script type="text/javascript">
function rectan()
{
var svgns = "http://www.w3.org/2000/svg";
for (var i = 0; i < 100; i++) {
var x = Math.random() * 5000,
y = Math.random() * 3000;
var rect = document.createElementNS(svgns, 'rect');
rect.setAttributeNS(null, 'x', x);
rect.setAttributeNS(null, 'y', y);
rect.setAttributeNS(null, 'height', '50');
rect.setAttributeNS(null, 'width', '50');
rect.setAttributeNS(null, 'fill', '#'+Math.round(0xffffff * Math.random()).toString(16));
document.getElementById('svgOne').appendChild(rect);
}
}
</script>
</head>
<body onload="rectan"();">
<svg id="svgOne" xmlns="http://www.w3.org/2000/svg" width="5000" height="3000">
<rect x="50" y="50"
width="50" height="50"
fill="black"
/>
</svg>
</body>
</html>
它所做的只是一個黑色矩形窗體SVG部分。我知道我在某個地方犯了一個錯誤,但我不知道在哪裏。
它可能是在黑色的背景上繪製黑色,嘗試設置背景說紅看看你是否看到你的矩形。 – Tom