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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.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_Iterator_Each - Fatal编程技术网

如何迭代jquery通配符选择器而不使用每个

如何迭代jquery通配符选择器而不使用每个,jquery,loops,iterator,each,Jquery,Loops,Iterator,Each,我必须用一个不同的迭代器遍历所有以“initial_”开头的ID 我目前尝试的是: counter = 5 $("[id^=initial_]").each(function () { while (counter > 0) { counter--; do some stuff here with the current id and manipulate counter } go to next id } 有关于如何做的建议吗?

我必须用一个不同的迭代器遍历所有以“initial_”开头的ID

我目前尝试的是:

counter = 5
$("[id^=initial_]").each(function () {
    while (counter > 0) {
        counter--;
        do some stuff here with the current id and manipulate counter
    }
    go to next id
}
有关于如何做的建议吗? 谢谢你的帮助

像这样试试

$("#yourid").each(function () {
   var counter = 5
        while (counter > 0) {
            counter--;
            do some stuff here with the current id and manipulate counter
        }
        go to next id
    }

我认为最好使用FOR而不是EACH and a WHILE
试试这个:

var arr = $("[id^=initial_]");
var i=0;
for(i=0;i<arr.length;i++){     
    $('#'+arr[i].id).html("I'm the number "+ (i+1))
}
var arr=$(“[id^=初始值]”);
var i=0;

对于(i=0;i为什么不能使用
.each()
?我不太明白你想做什么……你能不能用你想要实现的内容重新措辞或显示一些HTML标记?我正要添加更多信息,但@davide andreazzini马上就说到点子上了!谢谢你的关注tho@Gotrekk不过,您能告诉我为什么不想使用
.each()吗
?当然可以……因为我用一个外部ajax调用更改了计数器,我需要循环继续,而使用
each()
就不会了。非常感谢!你说到点子上了,它就像我想要的那样工作!