我对JS使用SVG.JS框架,我想为onclick
事件添加方法,对于selectColor
元素。javascript onclick和方法
changeCircleColor: function() {
this.circleColor = prompt("choose color for your circle");
},
view: function() {
var view = SVG('viewCircle').size(300, 300).style({
background: "black"
});
var circle = view.circle(280).attr({
fill: this.circleColor,
cx: "150",
cy: "150"
});
var selectColor = view.rect(30, 30).attr({
fill: "white",
x: "270",
y: "270",
stroke: "black",
onclick: "this.changeCircleColor()"
})
},
但脚本无法找到它。
CircleEditor.html:1 Uncaught TypeError: this.changeCircleColor is not a function at SVGRectElement.onclick (CircleEditor.html:1)
因为'this'点到窗口,但不是对象。如果您将这个对象分配给'window',因为你可以通过'onclick'属性来调用它。 –