1
可変円グラフ(円svg)をクラスpelClassに割り当てようとしています。何らかの理由で割り当てられていないため、多くの問題を引き起こしています。助けてください!SVG要素にクラスを割り当てる方法
function positionPellet()
{
constantCount = 1;
while(pelletCount < constantCount*3)
{
var pellet = document.createElementNS(xmlns, 'circle');
pellet.setAttribute('cx', Math.random() * window.innerWidth);
pellet.setAttribute('cy', Math.random() * window.innerHeight);
pellet.setAttribute('r' , 10);
pellet.className = "pelClass"; //Pellet Class Adding
pelletCount++;
pelletList = new Array(pelletCount);
pelletList.push(pellet);
svg.appendChild(pellet);
}
}
pelletList =新しいアレイ(HTMLと同じように機能します)のsetAttribute(pelletCount)を使用することができます。 ?本当に新しい配列を作成したいですか?おそらく、この文はループの前に実行されるべきです。 – user2182349
'pellet.class =" pelClass ";'を試しましたか?なぜあなたの問題を「クラスにクラスを割り当てようとしている」と記述しましたか? SVG要素にクラスを割り当てようとしてはいけませんか? –
適切に値をpelletCount、xmlns、およびsvgに割り当てると、コードが正常に動作しています。問題は何ですか? – Deep