基本选择器:直接根据id、CSS类名、元素名返回匹配的DOM元素。
层次选择器:也叫做路径选择器,可以根据路径层次来选择相应的DOM元素。
parent > child,prev + next ,prev ~ siblings
表单选择器: :input ,:text ,:password ,:radio ,:checkbox ,:submit 等;
过滤选择器:在前面的基础上过滤相关条件,得到匹配的DOM元素。
基本过滤器选择器::first,:last ,:not ,:even ,:odd ,:eq ,:gt ,:lt
内容过滤器选择器: :contains ,:empty ,:has ,:parent
可见性过滤器选择器::hidden ,:visible
属性过滤器选择器:[attribute] ,[attribute=value] ,[attribute!=value] ,[attribute^=value] ,[attribute$=value] ,[attribute*=value]
子元素过滤器选择器::nth-child ,:first-child ,:last-child ,:only-child
表单过滤器选择器::enabled ,:disabled ,:checked ,:selected
hover(fn1,fn2): 一个模仿悬停事件(鼠标移动到一个对象上面及移出这个对象)的方法。当鼠标移动到一个匹配的元素上面时,会触发指定的第一个函数。当鼠标移出这个元素时,会触发指定的第二个函数。
//当鼠标放在表格的某行上时将class置为over,离开时置为out。
$("tr").hover(function(){
$(this).addClass("over");
},
function(){
$(this).addClass("out");
});
toggle(evenFn,oddFn): 每次点击时切换要调用的函数。如果点击了一个匹配的元素,则触发指定的第一个函数,当再次点击同一元素时,则触发指定的第二个函数。随后的每次点击都重复对这两个函数的轮番调用。
//每次点击时轮换添加和删除名为selected的class。
$("p").toggle(function(){
$(this).addClass("selected");
},function(){
$(this).removeClass("selected");
});
原文:https://www.cnblogs.com/wangchangli/p/11279904.html