我想知道是否可以通过单击记录数组元素的数量。我在一个数组中有 100 多个元素:
var cubesmixed = [];
var cubes;
for(var i = 0; i < 143; i++) {
cubes = paper.rect(Math.floor(Math.random()*2000), Math.floor(Math.random()*2000), 0, 0);
cubes.animate({ width: 25, height: 25 }, 500, "bounce");
cubesmixed.push(cubes);
}
它们都是 svg 对象。如前所述,单击时我想获得该元素的数量。
$(this).click(function() { console.log(index of current element in cubes) });
提前致谢!