Javascript 如何处理jQuery每个循环中的n个元素?
我在Javascript 如何处理jQuery每个循环中的n个元素?,javascript,jquery-selectors,jquery,Javascript,Jquery Selectors,Jquery,我在循环中处理一系列元素,每个循环如下 function test(){ $('#first li').each(function(n){$(this).//here is the jQuery effects for nth li \\ here I want to process nth li of id="second" too }); 如何同时处理另一个id的第n个元素 例如,我想为DIVfirst和second的第一个lis生成jQuery效果;然后是两个div的第二个lis
循环中处理一系列元素,每个循环如下
function test(){
$('#first li').each(function(n){$(this).//here is the jQuery effects for nth li
\\ here I want to process nth li of id="second" too
});
如何同时处理另一个id的第n个元素
例如,我想为DIVfirst
和second
的第一个li
s生成jQuery效果;然后是两个div的第二个li
s
<div id="first">
<ul>
<li>something</li>
<li>something</li>
<li>something</li>
</ul>
</div>
<div id="second">
<ul>
<li>to be effect with 1st li of FIRST</li>
<li>to be effect with 2nd li of FIRST</li>
<li>to be effect with 3rd li of FIRST</li>
</ul>
</div>
- 某物
- 某物
- 某物
- 自第一个月的第一个月起生效
- 以第一个的第二个li生效
- 从第一个的第三个li开始生效
注:
应该是:
<div id="first">
<div id="second">
"first => "first"
"second => "second"
“first=>“first”
“秒=>“秒”
注:
应该是:
<div id="first">
<div id="second">
"first => "first"
"second => "second"
“first=>“first”
“秒=>“秒”
。each()提供索引作为第一个参数。它是以零为基础的索引。
.each()提供索引作为第一个参数。它是以零为基础的索引。
应该和
应该和
我相信他已经知道了,你可以在他的问题中看到他在使用索引
参数,他称之为n
。我相信他已经知道了,你可以在他的问题中看到他在使用索引
参数,他称之为n
。
<div id="first">
<div id="second">
"first => "first"
"second => "second"
function test(){
$('#first li').each(function(index, element){
$(this).bar(); // or $(element).bar();
$('#second li').eq(index).doSomething();
});
}