JQuery常用选择器(持续更新)

249 阅读1分钟

生活的乐趣取决于生活都本身,而不是取决于工作或地点。 —— 爱默生

前言:随着这些年前端发展的火热,曾经的大哥JQuery现在也没以前风光了,但仍然有大量的项目继续使用着,技术界日新月异的变化让人猝不及防,今日GitHub发布了移动端,收购了NPM,相信前端的生态和规范会越来越好,一个段子说,以后大家都是微软程序员哈哈

送上常用选择器,持续更新...

选择器 实例 获取
* $("*") 所有元素
#id $("#lastname") id="lastname" 的元素
.class $(".intro") 所有class="intro" 的元素
element $("p") 所有 <p> 元素
.class.class $(".test.demo") 所有class="test"class="demo" 的元素
:first $("p:first") 第一个<p> 元素
:last $("p:last") 最后一个<p> 元素
:even $("tr:even") 所有偶数 <tr> 元素
:odd $("tr:odd") 所有奇数 <tr> 元素
:eq(index) $("ul li:eq(3)") 列表中的第四个元素(index 从 0 开始)
:gt(no) $("ul li:gt(3)") 列出 index 大于 3 的元素
:lt(no) $("ul li:lt(3)") 列出 index 小于 3 的元素
:not(selector) $("input:not(:empty)") 所有不为空的input 元素
:header $(":header") 所有标题元素<h1> - <h6>
:animated $(":animated") 所有动画元素
:contains(text) $(":contains('text')") 包含指定字符串的所有元素
:empty $(":empty") 无子(元素)节点的所有元素
:hidden $("p:hidden") 所有隐藏的 <p> 元素
:visible $("table:visible") 所有可见的表格
s1,s2,s3 $("th,td,.intro") 所有带有匹配选择的元素
[attribute] $("[href]") 所有带有href属性的元素
[attribute=value] $("[href='#']") 所有href 属性的值等于"#"的元素
[attribute!=value] $("[href!='#']") 所有href 属性的值不等于"#"的元素
[attribute$=value] $("[href$='.jpg']") 所有href属性的值包含以".jpg" 结尾的元素
:input $(":input") 所有<input>元素
:text $(":text") 所有type="text"<input> 元素
:password $(":password") 所有type="password"<input> 元素
:radio $(":radio") 所有type="radio"<input> 元素
:checkbox $(":checkbox") 所有type="checkbox"<input> 元素
:submit $(":submit") 所有type="submit"<input> 元素
:reset $(":reset") 所有type="reset"<input> 元素
:button $(":button") 所有 type="button"<input> 元素
:image $(":image") 所有type="image"<input> 元素
:file $(":file") 所有type="file"<input> 元素
:enabled $(":enabled") 所有激活的input 元素
:disabled $(":disabled") 所有禁用的input 元素
:selected $(":selected") 所有被选取的input 元素
:checked $(":checked") 所有被选中的input 元素