Home  >  Article  >  Web Front-end  >  jquery索引在使用中的一些困惑_jquery

jquery索引在使用中的一些困惑_jquery

WBOY
WBOYOriginal
2016-05-16 17:18:481096browse

今日同事很正式的向我提出了两个关于jquery的问题,我也很正式得做了回答,顺便把源码贴到这里希望对朋友们有所帮助:

复制代码 代码如下:















问题一:为什么现在弹出来每个button(在ul>li中的)的索引值都是零,为什么不是从0-9排列的;
答:第一个匹配元素的 index,相对于同胞元素,获得第一个匹配元素相对于其同胞元素的 index 位置。请注意是"同胞".
复制代码 代码如下:

























问题二:为什么在button不在ul>li中,并且每个button后面加
的时候,弹出button的索引值翻了一倍,是从0-18的啊?
答:因为
也是同胞元素.

以下是在百度百科中查到的"同胞"的含义:
同父母所生的,例如同胞兄弟;
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn