jQuery基础教程笔记.docx
《jQuery基础教程笔记.docx》由会员分享,可在线阅读,更多相关《jQuery基础教程笔记.docx(16页珍藏版)》请在冰豆网上搜索。
jQuery基础教程笔记
jQuery基础教程笔记
看完jquery基础教程做的笔记,笔记并不适合所有人,觉得好,可以看,觉得不好,可以不看。
1,:
eq()和nth-child()
看下面代码:
$(function(){
$("#selected-plays>li:
eq
(1)").addClass("a");
//等价于$("#selected-plays>li:
nth-child
(2)").addClass("a");
//注意:
js数组是从0开始的,所以eq
(1)是取第二个元素。
//而css选择器:
nth-child()是从1开始的,所以要选择第二个元素,得使用:
nth-child
(2),而不是:
nth-child
(1)。
})
2,:
odd和:
even
:
odd:
奇数行
:
even:
偶数行
新手经常会说,好像跟我们做的相反?
其实与:
eq()选择器一样,下标都是从0开始的,
也就是表格的第一行编号是0(偶数);
第二行编号是1(奇数);以此类推。
。
。
3,$("tr:
odd").addClass()
可以写成$("tr").filter(":
odd").addClass()
4,$('td:
contains("cssrain")')//取得包含字符串cssrain的所有td
5,jquery转dom:
$("td").get(0).tagName或$("td")[0].tagName
6,load():
jquery中的load()有2层意思,
第一层意思可以等价于dom中window.onload
第二层意思可以load(url)。
7:
ready简写:
1;
$(document).ready(function(){
//dosomething
})
2;
$().ready(function(){
//dosomething
})
3;
$(function(){
//dosomething
})
8,事件冒泡:
正常的来说:
点击B会触发a的click。
如果我们不想触发A,可以用stopPropagation()阻止冒泡.
具体例子:
aaaaaaa
bbbbbbbb