用RaphaelJS庫繪製一組圓。onclick函數的參數
對於每個圓圈,我想創建一個傳遞變量的onclick
函數,但在此函數中,我的變量未定義。
什麼問題?
這是我的代碼:
//children is an array such as [1,2,4[5,6,7]]
for (var i = 0; i < children.length; i++) {
var array = children;
alert("ARRAY[0]===" + array[0])
var st = space2Draw.set();
st.push(space2Draw.circle(xChildren, yChildren, 20).click(function (array) {
//array[i] is undefined
alert("ARRAY[i]===" + array[i]);
//retrive(array[i]);
}),
LineRoot(xRadice, yRadice, xChildren, yChildren, space2Draw));
space2Draw.text(xChildren, yChildren, children[i]).attr({
fill: "white"
});
st.attr({
fill: "red"
});
xChildren += 50;
}