小白教程
所有教程
关于
Search
172.70.126.201
172.70.126.201
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“JQuery 选择器”的源代码
本页内容
上一节:
JQuery_实例
下一节:
JQuery_事件方法
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:jQuery 选择器}}[[Category:jQuery 教程|32]] = jQuery 选择器 = == jQuery 选择器 == 请使用我们的 [[trysel.php|jQuery 选择器检测器]] 来演示不同的选择器。 {| class="table table-striped table-hover" ! 选择器 ! 实例 ! 选取 |- | [[jq sel all|*]] | $("*") | 所有元素 |- | [[jq sel id|#id]] | $("#lastname") | id="lastname" 的元素 |- | [[jq sel class|.class]] | $(".intro") | class="intro" 的所有元素 |- | [[sel multiple classes|.class,.class]] | $(".intro,.demo") | class 为 "intro" 或 "demo" 的所有元素 |- | [[jq sel element|element]] | $("p") | 所有 <p> 元素 |- | [[sel multiple elements|el1,el2,el3]] | $("h1,div,p") | 所有 <h1>、<div> 和 <p> 元素 |- | | | |- | [[sel first|:first]] | $("p:first") | 第一个 <p> 元素 |- | [[sel last|:last]] | $("p:last") | 最后一个 <p> 元素 |- | [[sel even|:even]] | $("tr:even") | 所有偶数 <tr> 元素,索引值从 0 开始,第一个元素是偶数 (0),第二个元素是奇数 (1),以此类推。 |- | [[sel odd|:odd]] | $("tr:odd") | 所有奇数 <tr> 元素,索引值从 0 开始,第一个元素是偶数 (0),第二个元素是奇数 (1),以此类推。 |- | | | |- | [[jq sel firstchild|:first-child]] | $("p:first-child") | 属于其父元素的第一个子元素的所有 <p> 元素 |- | [[sel firstoftype|:first-of-type]] | $("p:first-of-type") | 属于其父元素的第一个 <p> 元素的所有 <p> 元素 |- | [[sel lastchild|:last-child]] | $("p:last-child") | 属于其父元素的最后一个子元素的所有 <p> 元素 |- | [[sel lastoftype|:last-of-type]] | $("p:last-of-type") | 属于其父元素的最后一个 <p> 元素的所有 <p> 元素 |- | [[sel nthchild|:nth-child(n)]] | $("p:nth-child(2)") | 属于其父元素的第二个子元素的所有 <p> 元素 |- | [[sel nthlastchild|:nth-last-child(n)]] | $("p:nth-last-child(2)") | 属于其父元素的第二个子元素的所有 <p> 元素,从最后一个子元素开始计数 |- | [[sel nthoftype|:nth-of-type(n)]] | $("p:nth-of-type(2)") | 属于其父元素的第二个 <p> 元素的所有 <p> 元素 |- | [[sel nthlastoftype|:nth-last-of-type(n)]] | $("p:nth-last-of-type(2)") | 属于其父元素的第二个 <p> 元素的所有 <p> 元素,从最后一个子元素开始计数 |- | [[sel onlychild|:only-child]] | $("p:only-child") | 属于其父元素的唯一子元素的所有 <p> 元素 |- | [[sel onlyoftype|:only-of-type]] | $("p:only-of-type") | 属于其父元素的特定类型的唯一子元素的所有 <p> 元素 |- | | | |- | [[sel parent child|parent > child]] | $("div > p") | <div> 元素的直接子元素的所有 <p> 元素 |- | [[sel parent descendant|parent descendant]] | $("div p") | <div> 元素的后代的所有 <p> 元素 |- | [[sel previous next|element + next]] | $("div + p") | 每个 <div> 元素相邻的下一个 <p> 元素 |- | [[sel previous siblings|element ~ siblings]] | $("div ~ p") | <div> 元素同级的所有 <p> 元素 |- | | | |- | [[sel eq|:eq(index)]] | $("ul li:eq(3)") | 列表中的第四个元素(index 值从 0 开始) |- | [[sel gt|:gt(no)]] | $("ul li:gt(3)") | 列举 index 大于 3 的元素 |- | [[sel lt|:lt(no)]] | $("ul li:lt(3)") | 列举 index 小于 3 的元素 |- | [[jq sel not|:not(selector)]] | $("input:not(:empty)") | 所有不为空的输入元素 |- | | | |- | [[sel header|:header]] | $(":header") | 所有标题元素 <h1>, <h2> ... |- | [[sel animated|:animated]] | $(":animated") | 所有动画元素 |- | [[jq sel focus|:focus]] | $(":focus") | 当前具有焦点的元素 |- | [[sel contains|:contains(text)]] | $(":contains('Hello')") | 所有包含文本 "Hello" 的元素 |- | [[sel has|:has(selector)]] | $("div:has(p)") | 所有包含有 <p> 元素在其内的 <div> 元素 |- | [[jq sel empty|:empty]] | $(":empty") | 所有空元素 |- | [[sel parent|:parent]] | $(":parent") | 匹配所有含有子元素或者文本的父元素。 |- | [[sel hidden|:hidden]] | $("p:hidden") | 所有隐藏的 <p> 元素 |- | [[sel visible|:visible]] | $("table:visible") | 所有可见的表格 |- | [[jq sel root|:root]] | $(":root") | 文档的根元素 |- | [[jq sel lang|:lang(language)]] | $("p:lang(de)") | 所有 lang 属性值为 "de" 的 <p> 元素 |- | | | |- | [[jq sel attribute|[attribute]]] | $("[href]") | 所有带有 href 属性的元素 |- | [[sel attribute equal value|[attribute=value]]] | $("[href='default.htm']") | 所有带有 href 属性且值等于 "default.htm" 的元素 |- | [[sel attribute notequal value|[attribute!=value]]] | $("[href!='default.htm']") | 所有带有 href 属性且值不等于 "default.htm" 的元素 |- | [[sel attribute end value|[attribute$=value]]] | $("[href$='.jpg']") | 所有带有 href 属性且值以 ".jpg" 结尾的元素 |- | [[sel attribute prefix value|[attribute|=value]]] | $("[title|='Tomorrow']") | 所有带有 title 属性且值等于 'Tomorrow' 或者以 'Tomorrow' 后跟连接符作为开头的字符串 |- | [[sel attribute beginning value|[attribute^=value]]] | $("[title^='Tom']") | 所有带有 title 属性且值以 "Tom" 开头的元素 |- | [[sel attribute contains value|[attribute~=value]]] | $("[title~='hello']") | 所有带有 title 属性且值包含单词 "hello" 的元素 |- | [[sel attribute contains string value|[attribute*=value]]] | $("[title*='hello']") | 所有带有 title 属性且值包含字符串 "hello" 的元素 |- | [[sel multipleattribute equal value|[name=value][name2=value2]]] | $( "input[id][name$='man']" ) | 带有 id 属性,并且 name 属性以 man 结尾的输入框 |- | | | |- | [[sel input|:input]] | $(":input") | 所有 input 元素 |- | [[sel input text|:text]] | $(":text") | 所有带有 type="text" 的 input 元素 |- | [[sel input password|:password]] | $(":password") | 所有带有 type="password" 的 input 元素 |- | [[sel input radio|:radio]] | $(":radio") | 所有带有 type="radio" 的 input 元素 |- | [[sel input checkbox|:checkbox]] | $(":checkbox") | 所有带有 type="checkbox" 的 input 元素 |- | [[sel input submit|:submit]] | $(":submit") | 所有带有 type="submit" 的 input 元素 |- | [[sel input reset|:reset]] | $(":reset") | 所有带有 type="reset" 的 input 元素 |- | [[sel input button|:button]] | $(":button") | 所有带有 type="button" 的 input 元素 |- | [[sel input image|:image]] | $(":image") | 所有带有 type="image" 的 input 元素 |- | [[sel input file|:file]] | $(":file") | 所有带有 type="file" 的 input 元素 |- | [[sel input enabled|:enabled]] | $(":enabled") | 所有启用的元素 |- | [[sel input disabled|:disabled]] | $(":disabled") | 所有禁用的元素 |- | [[sel input selected|:selected]] | $(":selected") | 所有选定的下拉列表元素 |- | [[sel input checked|:checked]] | $(":checked") | 所有选中的复选框选项 |- | .selector | $(selector).selector | 在jQuery 1.7中已经不被赞成使用。返回传给jQuery()的原始选择器 |- | [[jq sel target|:target]] | $( "p:target" ) | 选择器将选中ID和URI中一个格式化的标识符相匹配的<p>元素 |}
返回至“
JQuery 选择器
”。
上一节:
JQuery_实例
下一节:
JQuery_事件方法