javascriptでSVGを操作する際に問題があります。私は、ボタンをクリックすることによって、行の長さを増やしたいと思います。私は頭のタグにこのコードを含めました:SVGのスクリプティングに問題がある
<script type="text/javascript">
x=135;
y=135;
var container = document.getElementById("svgbox");
var mySvg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
function svg() {
mySvg.setAttribute("version", "1.2");
mySvg.setAttribute("baseProfile", "tiny");
mySvg.setAttribute("height","300px");
mySvg.setAttribute("width","300px");
container.appendChild(mySvg);
}
function line() {
x=x-10;
y=y-10;
var L1 = document.createElementNS("http://www.w3.org/2000/svg", "line");
L1.setAttribute("x1", "100"); L1.setAttribute("y1", "100");
L1.setAttribute("x2", x); L1.setAttribute("y2", y);
L1.setAttribute("stroke", "#05adc7");
L1.setAttribute("stroke-width", "2px");
mySvg.appendChild(L1);
}
</script>
これは、本文テキストです:
<body onload="svg()">
<form>
<input type="button" onClick="line()" />
</form>
<div id="svgbox">
</div>
</body>
しかし、私はボタンをクリックしたときに、私は、変数「コンテナことを私に言ってエラーが出ます" 無効である。誰が問題が何であるか知っていますか?
これは機能しました。助けてくれてありがとう。 – dopatraman