jQuery中$.each()函数的用法引申实例

jQuery中$.each()函数的用法引申实例

语法:

$.each( collection, callback(indexInArray, valueOfElement) )

值得一提的是,forEach 可以很方便的遍历数组和 NodeList ,jQuery 中的 jQuery 对象本身已经部署了这类遍历方法,而在原生 JavaScript 中则可以使用 forEach 方法,但是 IE 并不支持,因此我们可以手动把 forEach 方法部署到数组和 NodeList 中:

if ( !Array.prototype.forEach ){
Array.prototype.forEach = function(fn, scope) {
for( var i = 0, len = this.length; i

© 版权声明

相关文章

暂无评论

none
暂无评论...