第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用ES6純Javascript將路徑數(shù)組中的html集合(img)的src屬性設(shè)置為在每個

使用ES6純Javascript將路徑數(shù)組中的html集合(img)的src屬性設(shè)置為在每個

Qyouu 2022-09-02 16:20:56
我有一個src值數(shù)組,如[path1,path2,path3]和一個與arr值相同的數(shù)組長度的html集合。因此,我想傳遞每個值來設(shè)置html元素的src。我該怎么辦?我嘗試了 forEach,for Of,map,但它仍然是同一路徑中的所有元素,或者只是設(shè)置了一個(第一個元素)。//My code now<img alt='first-in-collection'><img alt='second-in-collection'><img alt='third-in-collection'> //The variablelet arr = ['path1', 'path2', 'path3']//Expected result <img src='path1' alt='first-in-collection'><img src='path2' alt='second-in-collection'><img src='path3' alt='third-in-collection'>
查看完整描述

1 回答

?
12345678_0001

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>


查看完整回答
反對 回復(fù) 2022-09-02
  • 1 回答
  • 0 關(guān)注
  • 146 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號