在线API
http://tool.oschina.net/apidocs/apidoc?api=jquery
-----------body onload-------------
$(fn)
是$(document).ready(fn)的简写
-----------基础选择器-------------
$()函数
传入的都是字符串,jquery内部进行正则表达式匹配
//id选择器
$("#id")
//class选择器
$(".class")
//标签选择器
$("div")
//选中所有
$("*")
//多选
$("span,.class")
--------关系过滤----------
都选择了两次
//选中子孙
$("body div")
//选中孩子
$("body>div")
//选中下一个弟弟
$(".two+div")
//选中所有弟弟
$(".two~*")
--------索引过滤-----------
//第一个
$("div:first").css("background-color","bisque")
//最后一个
$("div:last").css("background-color","cadetblue")
//偶数
$("div:even").css("background-color","#000000")
//奇数
$("div:odd").css("background-color","coral")
//索引=
$("div:eq(1)").css("background-color","aqua")
//>
$("div:gt(4)").css("background-color","red")
//<
$("div:lt(4)").css("background-color","darkgrey")
//not 参数为选择器
$("div:not(:first,:last)").css("background-color","azure")
---------索引过滤强化版-------------
//所有ul下的第一个li
$("ul>li:first-child").css("background-color", "aquamarine")
//从参数1开始,所有ul下的第n个li
$("ul>li:nth-child(2)").css("background-color","cadetblue")
//从参数1开始,所有ul下的所有3的倍数的li
$("ul>li:nth-child(3n)").css("background-color","cadetblue")
-------------内容过滤--------------
//不含节点,文本
$("div:empty").css("background-color","aquamarine")
//所有子孙含有该文本的节点
$("div:contains('11')").css("background-color","#000000")
//所有子孙含有该节点的节点
$("div:has(a)").css("background-color","red")
-----------属性过滤-----------
$("input[type='button']").click(function() {
if($("input[type='password']:first").val() == $("input[type='password']:last").val()) {
//id以cb开头(正则表达式的符号)
console.info($("input[id^='cb']"))
//多个条件过滤
console.info($("input[id^='cb'][name='aihao']"))
} else {
alert("两次密码不相同")
}
})
---------表单过滤(属性过滤专业版)---------
type属性:
:input
:text
:password
:radio
:checkbox
:submit
:image
:reset
:button
:file
:hidden
其他属性:
:enabled
:disabled
:checked
:selected
---------节点的显示与隐藏-----------
$("ul:gt(1)").css("display", "none")
$("button").click(function() {
if($(this).text() == "显示") {
$(":hidden").show()
$(this).text("隐藏")
}else{
$("ul:gt(1)").hide()
$(this).text("显示")
}
})