一、选择器
1.基本选择器
$("#id") //ID选择器
$("div") //元素选择器
$(".classname") //类选择器
$(".classname,.classname1,#id1") //组合选择器
2.层次选择器
$("#id>.classname ") //子元素选择器
$("#id .classname ") //后代元素选择器
$("#id + .classname ") //紧邻下一个元素选择器
$("#id ~ .classname ") //兄弟元素选择器
3.过滤选择器(重点)
$("li:first") //第一个li
$("li:last") //最后一个li
$("li:even") //挑选下标为偶数的li
$("li:odd") //挑选下标为奇数的li
$("li:eq(4)") //下标等于4的li
$("li:gt(2)") //下标大于2的li
$("li:lt(2)") //下标小于2的li
$("li:not(#runoob)") //挑选除 id="runoob" 以外的所有li
3.1.1是第一个&&第一个为<p>
$("p:first-child") // <p> 的父元素中第一个&&并且为 <p> 的元素
$("p:last-child") // <p> 的父元素的最后一个&&并且为<p> 的子元素
$("p:nth-child(3)") // <p> 的父元素的第三个&&并且为<p> 的子元素
$("p:nth-last-child(3)") // <p> 的父元素的倒数第三个&&并且为<p> 的子元素
$("p:only-child") // <p> 的父元素的唯一子元素&&并且为<p> 元素
3.1.2第一个<p>
$("p:first-of-type") //<p>的父元素的第一个 <p> 元素的每个 <p> 元素
$("p:last-of-type") //<p>的父元素的最后一个 <p> 元素的每个 <p> 元素
$("p:nth-of-type(3)") //<p>的父元素的第三个 <p> 元素的每个 <p> 元素
$("p:nth-last-of-type(3)") //<p>的父元素的倒数第三个 <p> 元素的每个 <p> 元素
$("p:only-of-type") // <p>的父元素的唯一 <p> 元素的每个 <p> 元素
3.2内容过滤选择器
$("div:contains('Runob')") // 包含 Runob文本的元素
$("td:empty") //不包含子元素或者文本的空元素
$("div:has(selector)") //含有选择器所匹配的元素
$("td:parent") //含有子元素或者文本的元素
3.3可见性过滤选择器
$("li:hidden") //匹配所有不可见元素,或type为hidden的元素
$("li:visible") //匹配所有可见元素
3.4属性过滤选择器
$("div[id]") //所有含有 id 属性的 div 元素
$("div[id='123']") // id属性值为123的div 元素
$("div[id!='123']") // id属性值不等于123的div 元素
$("div[id^='qq']") // id属性值以qq开头的div 元素
$("div[id$='zz']") // id属性值以zz结尾的div 元素
$("div[id*='bb']") // id属性值包含bb的div 元素
$("input[id][name$='man']") //多属性选过滤,同时满足两个属性的条件的元素
3.5状态过滤选择器
$("input:enabled") // 匹配可用的 input
$("input:disabled") // 匹配不可用的 input
$("input:checked") // 匹配选中的 input
$("option:selected") // 匹配选中的 option
4.表单选择器
$(":input") //匹配所有 input, textarea, select 和 button 元素
$(":text") //所有的单行文本框,$(":text") 等价于$("[type=text]"),推荐使用$("input:text")效率更高,下同
$(":password") //所有密码框
$(":radio") //所有单选按钮
$(":checkbox") //所有复选框
$(":submit") //所有提交按钮
$(":reset") //所有重置按钮
$(":button") //所有button按钮
$(":file") //所有文件域
5.其他选择器
$(":root") //HTML
$("p:lang(it)") //所有 lang 属性为 "it" 的 <p> 元素
二、事件
$(selector).blur() //为被选元素触发 blur 事件
$(selector).blur(function) //添加函数到 blur 事件
$(selector).focus() //触发被选元素的 focus 事件
$(selector).focus(function) //添加函数到 focus 事件
$(selector).click() //触发被选元素的 click 事件
$(selector).click(function) //添加函数到 click 事件
$(selector).dblclick() //触发被选元素的 dblclick 事件
$(selector).dblclick(function) //添加函数到 dblclick 事件
$(selector).keydown() //触发被选元素的 keydown 事件 键按下的过程
$(selector).keydown(function) //添加函数到 keydown 事件
$(selector).keyup() //触发被选元素的 keyup 事件 键被松开
$(selector).keyup(function) //添加函数到 keyup 事件
$(selector).keypress() //触发被选元素的 keypress 事件 键被按下
$(selector).keypress(function) //添加函数到 keypress 事件
$(selector).on(event,childSelector,data,function) //事件绑定
$(selector).off(event,selector,function(eventObj),map) //移除on增加的事件
$(selector).one(event,data,function) //当使用 one() 方法时,每个元素只能运行一次事件处理程序函数。
$(selector).mousedown() //触发被选元素的 mousedown 事件 当鼠标指针移动到元素上方,并按下鼠标左键时,会发生 mousedown 事件
$(selector).mousedown(function) //添加函数到 mousedown 事件
$(selector).mouseup() //触发被选元素的 mouseup 事件 当鼠标指针移动到元素上方,并松开鼠标左键时,会发生 mouseup 事件。
$(selector).mouseup(function) //添加函数到 mouseup 事件
$(selector).mouseenter() //触发被选元素的 mouseenter 事件 mouseenter 事件只有在鼠标指针进入被选元素时被触发
$(selector).mouseenter(function) //添加函数到 mouseenter 事件
$(selector).mouseleave() //触发被选元素的 mouseenter 事件 mouseleave 事件只有在鼠标指针离开被选元素时被触发
$(selector).mouseleave(function) //添加函数到 mouseenter 事件
$(selector).mouseover() //触发被选元素的 mouseover 事件 mouseover 事件在鼠标指针进入被选元素或任意子元素时都会被触发
$(selector).mouseover(function) //添加函数到 mouseover 事件
$(selector).mouseout() //触发被选元素的 mouseout 事件 mouseout 事件在鼠标指针离开被选元素或任意子元素时都会被触发
$(selector).mouseout(function) //添加函数到 mouseout 事件
$(document).ready(function)
$(function) //ready() 方法只能用于当前文档,因此无需选择器;两种方法一样
$(selector).resize() //触发被选元素的 resize 事件 当调整浏览器窗口大小时,发生 resize 事件。
$(selector).resize(function) //添加函数到 resize 事件
$(selector).scroll() //触发被选元素的 scroll 事件 当用户滚动指定的元素时,会发生 scroll 事件。
$(selector).scroll(function) //添加函数到 scroll 事件
$(selector).select() //触发被选元素的 select 事件 当 textarea 或文本类型的 input 元素中的文本被选择(标记)时,会发生 select 事件。
$(selector).select(function) //添加函数到 select 事件
$(selector).trigger(event,eventObj,param1,param2,...) //rigger() 方法触发被选元素上指定的事件以及事件的默认行为(比如表单提交)。
on示例
$("body").on('click','div',{msg: "You just clicked me!"},function(event){console.log(event);console.log(event.data.msg)})
三、遍历方法