如何迭代jquery通配符选择器而不使用每个
我必须用一个不同的迭代器遍历所有以“initial_”开头的ID 我目前尝试的是:如何迭代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 } 有关于如何做的建议吗?
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()
就不会了。非常感谢!你说到点子上了,它就像我想要的那样工作!