Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 使用循环,而不是手动重复每一行并更改编号_Jquery_Loops - Fatal编程技术网

Jquery 使用循环,而不是手动重复每一行并更改编号

Jquery 使用循环,而不是手动重复每一行并更改编号,jquery,loops,Jquery,Loops,我在赔率1、3、5等中都有编号为1-9和ulid1-17的ID 我知道我可以在这里使用循环,而不是手动重复每一行并更改编号,有人能帮我开始编写jQuery吗 $("div.text-right#top-1").append(vwo_$("ul#ul-1 li:first-child")); $("div.text-right#top-2").append(vwo_$("ul#ul-3 li:first-child")); $("div.text-right#top-3").append(vwo_

我在赔率1、3、5等中都有编号为1-9和
ul
id1-17的ID

我知道我可以在这里使用循环,而不是手动重复每一行并更改编号,有人能帮我开始编写jQuery吗

$("div.text-right#top-1").append(vwo_$("ul#ul-1 li:first-child"));
$("div.text-right#top-2").append(vwo_$("ul#ul-3 li:first-child"));
$("div.text-right#top-3").append(vwo_$("ul#ul-5 li:first-child"));
$("div.text-right#top-4").append(vwo_$("ul#ul-7 li:first-child"));
$("div.text-right#top-5").append(vwo_$("ul#ul-9 li:first-child"));
$("div.text-right#top-6").append(vwo_$("ul#ul-11 li:first-child"));
$("div.text-right#top-7").append(vwo_$("ul#ul-13 li:first-child"));
$("div.text-right#top-8").append(vwo_$("ul#ul-15 li:first-child"));
$("div.text-right#top-9").append(vwo_$("ul#ul-17 li:first-child"));

这是一个简单的
for
循环:

for(var i = 1; i < 10; i++) {
    $("div.text-right#top-" + i).append($("ul#ul-" + (i*2-1) + " li:first-child"));
}
for(变量i=1;i<10;i++){
$($div.text-right#top-“+i”).append($($ul#ul-“+(i*2-1)+“li:第一个孩子”);
}

这是一个简单的
循环:

for(var i = 1; i < 10; i++) {
    $("div.text-right#top-" + i).append($("ul#ul-" + (i*2-1) + " li:first-child"));
}
for(变量i=1;i<10;i++){
$($div.text-right#top-“+i”).append($($ul#ul-“+(i*2-1)+“li:第一个孩子”);
}

第一次使用
i
,第二次使用
i*2-1
您当然可以使用循环来完成这项工作,但是使用DOM遍历会更好,因为它更健壮,更易于维护。如果您可以在问题中添加一个HTML示例,我可以给您一个如何执行此操作的示例,第一个使用
I
,第二个使用
I*2-1
,您肯定可以使用循环来执行此操作,但是使用DOM遍历会更好,因为它更健壮,更易于维护。如果你能在问题中添加一个YoutHTML示例,我可以给你举一个例子说明如何做到这一点