Created
July 10, 2014 23:24
-
-
Save jikeytang/5c0e699d88111bc61348 to your computer and use it in GitHub Desktop.
[ jQuery ] - 20140711-题目1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
请说出以下的区别: | |
1. $('p').get(), | |
2. $('p')[1], | |
3. $('p').eq(0), | |
4. $('p').index() | |
PS: | |
1. 回复时注意加上下面这句话,才会有语法高亮或格式缩进。 | |
```javascript | |
// you code | |
``` | |
2. 粘贴代码时请使用shift+tab,缩进前面的空白。 |
$('p').get()
获取文档所有p标签元素的数组
$('p')[1]
获取文档第二个p标签元素
$('p').eq(0)
获取文档第一个p标签元素的jQuery对象
$('p').index()
获取文档最后一个p标签元素相对于其第一个兄弟节点的位置
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
====>> get() 方法获得由选择器指定的 DOM 元素。
====>> 範例:获得第一个 p 元素的名称和值:
s[0]倒底是什么?(s为jQuery对象, 可隨意指定 dom 元素)
代码:var s=$("div"); alert(s.length);alert(s[0]);
jQuery对象默认都有个0索引,
s为jQuery对象
s[0]为Dom元素 可以用dom的所有属性和方法
可以根据length属性判断一共包含有多少个Dom元素对象。
取对象用:s[0],s[1],s[2]......
====>> 範例:
====>> :eq() 选择器选取带有指定 index 值的元素。
index 值从 0 开始,所有第一个元素的 index 值是 0(不是 1)。
====>> 範例:用 eq() 輸入索引值,找到 p 元素的第一個,再加上 css 設定
=====>> index() 方法返回指定元素相对于其他指定元素的 index 位置。
=====>> 範例:在li 點擊,返回其元素的索引值