当按下“清除”按钮时,我正在尝试清空包含绘制坐标的数组。
当我致电drawnDivs.clear()
时,我收到错误消息,表示它不是函数。 drawnDivs
肯定是一个数组,我有Firebug console.log
打印出来的东西。这是hosted here。
答案 0 :(得分:78)
不,不是。但是drawnDivs.length = 0
应该有用。
答案 1 :(得分:9)
drawnDivs = [];
答案 2 :(得分:4)
Stack Overflow问题 How do I empty an array in JavaScript? 回答了这个问题。
答案中有两个例子:
var A = ['some', 'values', 'here'];
//Method 1
//(This was my original answer to the question)
A = [];
// Method 2 (as suggested by Matthew Crumley)
A.length = 0
Axel Rauschmayer博士对这两种方法进行here is a nice write up。
答案 3 :(得分:2)
答案 4 :(得分:0)
您可以交替使用Prototype库,然后使用Prototype的clear()
方法。