我正在尝试使用RaphaëlJS库。我只想有一些圆圈,并在用户单击它们时更改其颜色。但是我不明白为什么我的代码不起作用。它出什么问题了?

在此处http://jsfiddle.net/Xj4GA/及以下进行编码。

 window.onload = function () {

                var paper = Raphael(0, 0, 640, 480);

                circles = paper.set();

                circles.push(paper.circle(20, 20, 10));
                circles.push(paper.circle(30, 30, 10));
                circles.push(paper.circle(50, 60, 10));
                circles.push(paper.circle(120, 420, 10));
                circles.push(paper.circle(520, 20, 10));
                circles.push(paper.circle(230, 280, 10));
                circles.push(paper.circle(320, 260, 10));

                for (var i = 0; i < circles.length; i++) {
                    circles[i].click(function () {
                        alert('balblaba');
                        //this.attr("stroke", "Red");
                    });
                }
}

最佳答案

填写circles.attr({fill: "red"});

10-07 18:59