this.alt = ‘这是第[‘+n+’]张图片,图片的id是’ + this.id;
})
$([1,2,3]).each(function(){alert(this);})
使用元素间关系获取jquery对象集
$(this).closest(‘div’)比如触发的按钮在哪个div中发生
$(this).siblings(‘button[title=”Close”]’)所有同级元素,不包含本身
$(this).children(‘.someclassname’)所有子节点元素,不包含重复子节点
$(this).closest(”)临近祖先元素
$(this).contents()由元素内容组成的jquery对象集,比如可以获取<iframe>元素内容
$(this).next(‘.someclassname’)下一个同级元素
$(this).nextAll()后面所有的同级元素
$(this).nextUntil(‘.someclassname’)后面所有的同级元素直到遇到目标元素
$(this).offsetParent()离jquery对象集最近的父辈元素
$(this).parent()直接父元素
$(this).parents()所有父元素
$(this).parrentsUntil()所有父元素,直到目标父元素
$(this).prev()上一个同级元素
$(this).prevAll()之前的所有同级元素
$(this).prevTntl()之前的所有同级元素,直到目标元素
其它获取jquery对象集的方式
$(this).find(p span)
判断是否是某个jquery对象集
var hasImg = $(‘*’).is(‘img’);
jquery方法:
$().hide()
$().addClass(”)
$().html(”)
$(‘a’).size()元素数量
jquery选择器:
$(‘p:even’)
$(‘tr:nth-child(1)’)
$(‘body > div’)直接子元素
$(‘a[href=$=’pdf’]’)根据属性选择
$(div:has(a))过滤
jquery函数:
$.trim()
jquery执行时间:
$(document).ready(function(){});
$(function(){});
创建DOM元素:
$(‘<p></p>’).insertAfter();
$(‘<img>’,{
src: ”,
alt: ”,
title: ”,
click: function(){}
}).css({
cursor:’pointer’,
border:”,
padding:”,
backgroundColor:’white’
}).append(”);










