来自API的图片未显示

Rah*_*hni 1 html javascript

我已经从API检索了一些图像,但是它们没有出现。绿色和蓝色的图像图标显示在我的网页上的位置上,而不是实际的图像显示。我需要更改/添加代码以显示图像吗?

let html = [];
fetch('https://api.nytimes.com/svc/topstories/v2/technology.json?api-key="*"')
.then((resp) => resp.json())
.then(function(data) {
 data.results.slice(0, 4).forEach(res => {
  html.push(`<h1>${res.title}</h1>`)
  html.push(`<p>${res.url}</p>`)
  html.push(`<p>${res.abstract}</p>`)
  html.push(`<p>${res.published_date}</p>`)
  html.push(`<img src='${res.multimedia[4]}.url'/>`) 
  })
  document.getElementById("res").innerHTML = html.join("")
  })


 
Run Code Online (Sandbox Code Playgroud)
     <html>
     <head>
        <script 
src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"> 
 </script>
    <script src="index.js"></script>
</head>
<body>
    <h1>Top Stories</h1>
<button class="accordion">Story 1</button>
<div class="panel">
  <div id="res"></div>
</div>

<button class="accordion">Story 2</button>
<div class="panel">
  <div id="accordion"></div>
</div>

<button class="accordion">Story 3</button>
<div class="panel">
  <div id="accordion"></div>
</div>
<button class="accordion">Story 4</button>
<div class="panel">
  <div id="accordion"></div>
</div>
</body>
Run Code Online (Sandbox Code Playgroud)

Saf*_*ees 5

我认为您需要在图像中添加src而不是像这样的值:

html.push(`<img src='${res.multimedia[4].url}'/>`)
Run Code Online (Sandbox Code Playgroud)