jQuery学习笔记--使用jQuery操作样式和属性

each函数的说明:

each( callback ) Returns: jQuery包装集

对包装集中的每一个元素执行callback方法. 其中callback方法接受一个参数, 表示当前遍历的索引值,从0开始.

           $("img").each(function(index) {
                alert("index:" + index + ", id:" + this.id + ", alt:" + this.alt);
                this.alt = "changed";
                alert("index:" + index + ", id:" + this.id + ", alt:" + this.alt);
            });

       在jQuery提供了each()函数用于遍历jQuery包装集, 其中的this指针是一个DOM对象, 所以我们可以应用这一点配合原生javascript来操作元素的DOM属性

你可能感兴趣的:(jquery)