例如:
let arr = [1, 2, 3, 4, 5]
arr.forEach(function(item, index) {
if (index === arr.length - 1) {
console.log('This is the last item!')
}
})
看你需不需要返回值,map返回的是新数组,比如你想让数组成员*2var a = [1, 2, 3, 4, 5]
var b = a.map(function (fn) {
return fn * 2
})
console.log(b)//Array(5) [2, 4, 6, 8, 10]
而for则是遍历每个数组成员
不能加onclick吗?你这个onclick后面为什么跟了一个return啊?要触发ch这个函数为什么要加这个东西啊?去掉试试。再一个如果去掉还不行的话那么你就给这个area加一个ID,然后这样document.getElementById("area的ID").onclick=ch("fd")就行了~肯定能用~放心吧~