1 回答
TA贡献1802条经验 获得超5个赞
无需同时在映像数组和路径数组上运行循环。在任何一个阵列上运行循环。继续递增迭代器计数,并设置当前迭代器索引图像的 src。
let arr = ['path1', 'path2', 'path3'];\
// get all images
let img = document.getElementsByClassName('img-thumbnail')
// initialize iterator with 0
let i=0;
for(let el of arr){
// set attribute of corresponding image
img[i++].setAttribute('src', el)
}
<div class="col-8">
<div class="row produit-desc-lense">
<div class="col-4 text-center border-bottom">
<img class="img-fluid rounded img-thumbnail" alt="/">
<h5>caméra 2</h5>
</div>
<div class="col-4 d-flex align-items-center justify-content-center border-bottom">
<p></p>
</div>
<div class="col-4 d-flex align-items-center justify-content-center border-bottom">
<select id="selectNumber">
<option>Choose a number</option>
</select>
</div>
</div><div class="row produit-desc-lense">
<div class="col-4 text-center border-bottom">
<img class="img-fluid rounded img-thumbnail" alt="/">
<h5>caméra 2</h5>
</div>
<div class="col-4 d-flex align-items-center justify-content-center border-bottom">
<p></p>
</div>
<div class="col-4 d-flex align-items-center justify-content-center border-bottom">
<select id="selectNumber">
<option>Choose a number</option>
</select>
</div>
</div><div class="row produit-desc-lense">
<div class="col-4 text-center border-bottom">
<img class="img-fluid rounded img-thumbnail" alt="/">
<h5>caméra 2</h5>
</div>
<div class="col-4 d-flex align-items-center justify-content-center border-bottom">
<p></p>
</div>
<div class="col-4 d-flex align-items-center justify-content-center border-bottom">
<select id="selectNumber">
<option>Choose a number</option>
</select>
</div>
</div>
</div>
添加回答
举报