【发布时间】:2021-07-08 09:03:59
【问题描述】:
如何完成执行功能,这样当点击 Next Image 按钮时,会显示 images 数组中的下一张图像,当我到达数组的末尾时,它应该从数组的开头开始数组.. 所以本质上,下一个图像按钮的作用就像是循环浏览图像数组中的图像的一种方式。 注意:数组第一个索引处的图像已经显示。所以当我点击按钮时,应该显示第二个索引处的图像..等等。
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<button onclick='execute()'>Next Image</button>
<div>
<img src='https://bocageanimalhospital.com/wp-content/uploads/2020/09/iconfinder_1F431-cat-face_4888130.png' />
</div>
</body>
<script>
const images = [
'https://bocageanimalhospital.com/wp-content/uploads/2020/09/iconfinder_1F431-cat-face_4888130.png',
'https://catdoctorofmonroe.com/wp-content/uploads/2020/09/iconfinder_1F408-cat-B_4888072.png',
'https://aux.iconspalace.com/uploads/cat-clean-icon-256.png'
]
function execute() {
}
</script>
</html>
【问题讨论】:
-
到目前为止你有什么尝试?
标签: javascript arrays image function attributes