直接看代碼:
// forEach方式
document.querySelectorAll('.ele').forEach(function() {
...
});
// 空數(shù)組方式call來進行: 不推薦, 因為占空間
[].forEach.call(elements, function(element) {
...
});
// 傳統(tǒng)方法
var len = element.length;
for (i = 0; i < len; ++i) {
...
}