1 回答

TA貢獻(xiàn)1802條經(jīng)驗 獲得超5個贊
無需同時在映像數(shù)組和路徑數(shù)組上運行循環(huán)。在任何一個陣列上運行循環(huán)。繼續(xù)遞增迭代器計數(shù),并設(shè)置當(dāng)前迭代器索引圖像的 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>
添加回答
舉報