我试过这段代码,我很确定这个函数工作得很好,它只是不输出我放在对象中的图像,所以有人可以帮助我做到这一点吗?到目前为止,这就是我所做的
<!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>
总结代码,它应该输出名称与用户输入匹配的图像
ABOUTYOU
相关分类