boh*_*han 16 javascript jquery loops jquery-selectors
我想迭代查询选择器的结果.
Html代码
<nav id="navigation">
<a href="#" tabindex="1" class="active_nav">nav1</a>
<a href="#" tabindex="2">nav2</a>
<a href="#"tabindex="3">nav3</a>
</nav>
Run Code Online (Sandbox Code Playgroud)
当我使用javascript
alert($("#navigation >a")[0]);
Run Code Online (Sandbox Code Playgroud)
结果是标签ahref属性我不知道为什么.
Sus*_* -- 21
使用 $.each
$("#navigation > a").each(function() {
console.log(this.href)
});
Run Code Online (Sandbox Code Playgroud)
$('#navigation > a')[0]
^ ^---- Selects the 1st dom object from the jQuery object
| that is nothing but the index of the element among
| the list of elements
|------- Gives you children of nav(3 anchor tags in this case) which is a
jQuery object that contains the list of matched elements
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18853 次 |
| 最近记录: |