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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

為什么我的 js 對(duì)象不輸出我放入其中的圖像

為什么我的 js 對(duì)象不輸出我放入其中的圖像

牛魔王的故事 2023-06-15 17:09:15
我試過(guò)這段代碼,我很確定這個(gè)函數(shù)工作得很好,它只是不輸出我放在對(duì)象中的圖像,所以有人可以幫助我做到這一點(diǎn)嗎?到目前為止,這就是我所做的<!DOCTYPE html><html><head>    <script>    function test() {        const test1 = window.prompt("Yay?nevi gir");        const correctNameBooks = books.filter(book => book.name === test1);        console.log(correctNameBooks);    }    let books = [        {            name: 'Tongu?',            imgUrl: 'https://i.redd.it/nv8gp4ms60161.png'        },        {            name: 'Nitelik',            imgUrl: 'https://i.redd.it/nlhp8ij770161.png'        },        {            name: "Sonu?",            imgUrl: 'https://i.redd.it/lhy1liao70161.png'        },        {            name: 'Supara',            imgUrl: 'https://i.redd.it/t7263o2c80161.png'        },        {            name: 'Palme',            imgUrl: 'https://i.redd.it/24gn3zdg80161.png'        },        {            name: 'Gezegen',            imgUrl: 'https://i.redd.it/ibqo7b9j80161.png'        },        {            name: 'Karek?k',            imgUrl: 'https://i.redd.it/dkos5tds80161.png'        },        {            name: 'Ar?',            imgUrl: 'https://i.redd.it/oer1chfv80161.png'        },        {            name: 'Okyanus',            imgUrl: 'https://i.redd.it/xkbv0gg290161.png'        },        {            name: 'H?z',            imgUrl: 'https://i.redd.it/w167386b90161.png'        },        {            name: 'S?nav',            imgUrl: 'https://i.redd.it/02md3r9d90161.png'        },        {            name: 'Esen',            imgUrl: 'https://i.redd.it/k4ars8mf90161.png'        }    ]</script></head>  <body>    <button id="btn" onclick=test()>test</button>  </body></html>總結(jié)代碼,它應(yīng)該輸出名稱與用戶輸入匹配的圖像
查看完整描述

1 回答

?
ABOUTYOU

TA貢獻(xiàn)1812條經(jīng)驗(yàn) 獲得超5個(gè)贊

要顯示圖像,您需要使用<img>HTML 中的標(biāo)簽。在此示例中,您可以擁有多本同名書(shū)籍。


更多解釋在評(píng)論中。


function test() {

    const test1 = window.prompt("Yay?nevi gir");

    const correctNameBooks = books.filter(book => book.name === test1);

    console.log(correctNameBooks);

    

    const imageContainer = document.querySelector("div#image-container"); // Grab the parent/container

    imageContainer.innerHTML = ""; // Remove all the children

    for (let book of correctNameBooks) {

        const newImage = document.createElement("img"); // Create a new image element/tag

        newImage.src = book.imgUrl; // Set its source to the book's image url

        imageContainer.appendChild(newImage); // Add the image to the image container's children

    }

}

let books = [

    {

        name: 'Tongu?',

        imgUrl: 'https://i.redd.it/nv8gp4ms60161.png'

    },

    {

        name: 'Nitelik',

        imgUrl: 'https://i.redd.it/nlhp8ij770161.png'

    },

    {

        name: "Sonu?",

        imgUrl: 'https://i.redd.it/lhy1liao70161.png'

    },

    {

        name: 'Supara',

        imgUrl: 'https://i.redd.it/t7263o2c80161.png'

    },

    {

        name: 'Palme',

        imgUrl: 'https://i.redd.it/24gn3zdg80161.png'

    },

    {

        name: 'Gezegen',

        imgUrl: 'https://i.redd.it/ibqo7b9j80161.png'

    },

    {

        name: 'Karek?k',

        imgUrl: 'https://i.redd.it/dkos5tds80161.png'

    },

    {

        name: 'Ar?',

        imgUrl: 'https://i.redd.it/oer1chfv80161.png'

    },

    {

        name: 'Okyanus',

        imgUrl: 'https://i.redd.it/xkbv0gg290161.png'

    },

    {

        name: 'H?z',

        imgUrl: 'https://i.redd.it/w167386b90161.png'

    },

    {

        name: 'S?nav',

        imgUrl: 'https://i.redd.it/02md3r9d90161.png'

    },

    {

        name: 'Esen',

        imgUrl: 'https://i.redd.it/k4ars8mf90161.png'

    }

]

<!DOCTYPE html>

<html>

<head>

</head>

  <body>

    <button id="btn" onclick=test()>test</button>

    <div id="image-container"></div>

  </body>

</html>


查看完整回答
反對(duì) 回復(fù) 2023-06-15
  • 1 回答
  • 0 關(guān)注
  • 175 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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