我在学习如何使用while loop
,并提出了一个场景,其中while loop
可能适用。JavaScript - while循环
假设20张左右的图片具有类似的URL被布置在一个页面象下面这样: http://img7.italian.uk/pastaimages/6253.jpg
http://img7.italian.uk/pastaimages/4218.jpg
http://img7.italian.uk/pastaimages/7657.jpg
...(根据该模式,仅URL的最后一部分是对于每个不同的图片)...
在所有以http://img7.italian.uk/pastaimages/*
开头的图片中,如果第一张图片是http://img7.italian.uk/pastaimages/6253.jpg
,只刷新当前页面。
只要第一张照片是“6253”,同样的动作就会重复出现。
但是,一旦第一张图片不再是“6253”之一,则停止循环,并单击具有http://img7.italian.uk/pastaimages/*
网址,如“3585”或8291等目前的第一张图片
我不知道怎么样去做这件事。
while (// 1st image === 6253) {
//refresh the current page
}
// once 1st image is no longer 6253, stop the loop and
// click the current first picture that ends with something like 3585, 8291 etc.
为什么不在循环中使用if?似乎只有当第一个图像具有特定ID时,才想继续迭代。 –