JavaScript——while循环

JavaScript——while循环,javascript,while-loop,Javascript,While Loop,我正在学习如何使用while loop,并提出了一个可能适用于while loop的场景 假设20张左右具有类似URL的图片排列在一个页面中,如下所示: http://img7.italian.uk/pastaimages/6253.jpg http://img7.italian.uk/pastaimages/4218.jpg http://img7.italian.uk/pastaimages/7657.jpg ... (根据这种模式,每个图片只有URL的最后一部分是不同的) 在所有以url开

我正在学习如何使用
while loop
,并提出了一个可能适用于
while loop
的场景

假设20张左右具有类似URL的图片排列在一个页面中,如下所示:
http://img7.italian.uk/pastaimages/6253.jpg

http://img7.italian.uk/pastaimages/4218.jpg

http://img7.italian.uk/pastaimages/7657.jpg

... (根据这种模式,每个图片只有URL的最后一部分是不同的)

在所有以url开头的图片中
http://img7.italian.uk/pastaimages/*
,如果第一个是
http://img7.italian.uk/pastaimages/6253.jpg
,只需刷新当前页面即可

只要第一张图片是“6253”,同样的动作就会重复

但一旦第一张图片不再是“6253”图片,则停止该循环并用
http://img7.italian.uk/pastaimages/*
url,如“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.

首先获取图像的src(我需要看到您的HTML,但它是这样的):

并将其作为条件应用于while循环:

while (imgSrc == 'http://img7.italian.uk/pastaimages/6253.jpg') {
    document.location.reload(); //refresh the current page
}
// loop stops automatically
不确定单击当前图片是什么意思


查看循环中的文档。

为什么不在循环中使用if?似乎仅当第一张图像具有特定id时,您才希望继续迭代。在页面中,最新图片(一旦可用)出现在页面的左上角(即第一个位置)。因此,以前最新的图片“6253”现在已移动到第二个位置(或第三个位置等…一旦页面中添加了另一张最新图片)。如何单击第一个位置的当前最新图片,该位置的数字如“3534”、“9043”或其他任何数字?所有图片都有相同的起始URL,只是最后一部分不同。谢谢,点击?你的意思是突出还是扩大?你试过使用图像插入符号吗?哦,图像是一个超链接,单击后会指向另一个页面。我想左键单击图像以转到下一页。我想这是我应该在这批代码末尾编写的命令,但不知道如何编写。所以你想要一个图像插入符号?你不能用javascript左键单击图像,你只能触发它的事件
while (imgSrc == 'http://img7.italian.uk/pastaimages/6253.jpg') {
    document.location.reload(); //refresh the current page
}
// loop stops automatically