最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501
当前位置: 首页 - 科技 - 知识百科 - 正文

juqery学习之三选择器层级基本_jquery

来源:懂视网 责编:小采 时间:2020-11-27 20:56:02
文档

juqery学习之三选择器层级基本_jquery

juqery学习之三选择器层级基本_jquery:#id 根据给定的ID匹配一个元素。 Matches a single element with the given id attribute. 返回值 Element 参数 id (String) : 用于搜索的,通过元素的 id 属性中给定的值 示例 查找 ID 为myDiv的元素。 HTML 代码: id=not
推荐度:
导读juqery学习之三选择器层级基本_jquery:#id 根据给定的ID匹配一个元素。 Matches a single element with the given id attribute. 返回值 Element 参数 id (String) : 用于搜索的,通过元素的 id 属性中给定的值 示例 查找 ID 为myDiv的元素。 HTML 代码: id=not

#id

根据给定的ID匹配一个元素。
Matches a single element with the given id attribute.

返回值

Element

参数

id (String) : 用于搜索的,通过元素的 id 属性中给定的值

示例

查找 ID 为"myDiv"的元素。

HTML 代码:

id="notMe"


id="myDiv"

jQuery 代码:

$("#myDiv");

结果:

[ id="myDiv" ]
---------------------------------------------------------------------------------------

element

根据给定的元素名匹配所有元素
Matches all elements with the given name.

返回值

Array

参数

element (String) : 一个用于搜索的元素。指向 DOM 节点的标签名。

示例

查找一个 DIV 元素。

HTML 代码:

DIV1
DIV2
SPAN

jQuery 代码:

$("div");

结果:

[ DIV1, DIV2 ] ---------------------------------------------------------------------------------------

.class

根据给定的类匹配元素。
Matches all elements with the given class.

返回值

Array

参数

class (String) : 一个用以搜索的类。一个元素可以有多个类,只要有一个符合就能被匹配到。

示例

查找所有类是 "myClass" 的元素.

HTML 代码:

div class="notMe"
div class="myClass"
span class="myClass"

jQuery 代码:

$(".myClass");

结果:

[ div class="myClass", span class="myClass" ]
---------------------------------------------------------------------------------------

*

匹配所有元素 多用于结合上下文来搜索。
Matches all elements. Most useful when combined with a context to search in.

返回值

Array

示例

找到每一个元素

HTML 代码:

DIV
SPAN

P

jQuery 代码:

$("*")

结果:

[ DIV, SPAN,

P

]
---------------------------------------------------------------------------------------

selector1,selector2,selectorN

将每一个选择器匹配到的元素合并后一起返回。 你可以指定任意多个选择器,并将匹配到的元素合并到一个结果内。
Matches the combined results of all the specified selectors. You can specify any number of selectors to combine into a single result.

返回值

Array

参数

selector1 (Selector) : 一个有效的选择器

selector2 (Selector) : 另一个有效的选择器

selectorN (Selector) : (可选) 任意多个有效选择器

示例

找到匹配任意一个类的元素。

HTML 代码:

div

p class="myClass"


span

p class="notMyClass"

jQuery 代码:

$("div,span,p.myClass")

结果:

[ div,

p class="myClass"

, span ] ---------------------------------------------------------------------------------------

ancestor descendant

在给定的祖先元素下匹配所有的后代元素
Matches all descendant elements specified by descendant of elements specified by ancestor.

返回值

Array

参数

ancestor (Selector) : 任何有效选择器

descendant (Selector) : 用以匹配元素的选择器,并且它是第一个选择器的后代元素

示例

找到表单中所有的 input 元素

HTML 代码:


jQuery 代码:

$("form input")

结果:

[ , ]
---------------------------------------------------------------------------------------

parent > child

在给定的父元素下匹配所有的子元素
Matches all child elements specified by child of elements specified by parent.

返回值

Array

参数

parent (Selector) : 任何有效选择器

child (Selector) : 用以匹配元素的选择器,并且它是第一个选择器的子元素

示例

匹配表单中所有的子级input元素。

HTML 代码:


jQuery 代码:

$("form > input")

结果:

[ ]
---------------------------------------------------------------------------------------

prev + next

匹配所有紧接在 prev 元素后的 next 元素
Matches all next elements specified by next that are next to elements specified by prev.

返回值

Array

参数

prev (Selector) : 任何有效选择器

next (Selector) :一个有效选择器并且紧接着第一个选择器

示例

匹配所有跟在 label 后面的 input 元素

HTML 代码:


jQuery 代码:

$("label + input")

结果:

[ , ]
---------------------------------------------------------------------------------------

prev ~ siblings

匹配 prev 元素之后的所有 siblings 元素
Matches all sibling elements after the "prev" element that match the filtering "siblings" selector.

返回值

Array

参数

prev (Selector) : 任何有效选择器

siblings (Selector) : 一个选择器,并且它作为第一个选择器的同辈

示例

找到所有与表单同辈的 input 元素

HTML 代码:


jQuery 代码:

$("form ~ input")

结果:

[ ]

声明:本网页内容旨在传播知识,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文档

juqery学习之三选择器层级基本_jquery

juqery学习之三选择器层级基本_jquery:#id 根据给定的ID匹配一个元素。 Matches a single element with the given id attribute. 返回值 Element 参数 id (String) : 用于搜索的,通过元素的 id 属性中给定的值 示例 查找 ID 为myDiv的元素。 HTML 代码: id=not
推荐度:
标签: 基本 层次 选择器
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top