Javascript API中的图像不显示
我从API中检索了一些图像,但它们没有出现。绿色和蓝色的图像图标出现在我的网页上,而不是实际的图像。我需要在代码中更改/添加什么才能显示图像 设html=[]; 取回https://api.nytimes.com/svc/topstories/v2/technology.json?api-键=*' .thenresp=>resp.json .Then函数数据{ data.results.slice0,4.forEachres=>{ html.push`${res.title}` html.push`${res.url}` html.push`${res.abstract}` html.push`${res.published\u date}` html.push` } document.getElementByIdres.innerHTML=html.join } 头条新闻 故事1 故事2 故事3 故事4 试试这个Javascript API中的图像不显示,javascript,html,Javascript,Html,我从API中检索了一些图像,但它们没有出现。绿色和蓝色的图像图标出现在我的网页上,而不是实际的图像。我需要在代码中更改/添加什么才能显示图像 设html=[]; 取回https://api.nytimes.com/svc/topstories/v2/technology.json?api-键=*' .thenresp=>resp.json .Then函数数据{ data.results.slice0,4.forEachres=>{ html.push`${res.title}` html.pu
html.push(`<img src='${res.multimedia[4]}'/>`)
而不是这个
html.push(`<image>${res.multimedia[4]}</image>`)
试试这个
html.push(`<img src='${res.multimedia[4]}'/>`)
而不是这个
html.push(`<image>${res.multimedia[4]}</image>`)
在HTML中,图像是用指定图像URL网址的属性定义的:
设html=[];
取回https://api.nytimes.com/svc/topstories/v2/technology.json?api-钥匙
.thenresponse=>response.json
.thendata=>{
//打印getRequest中“response.json”的结果
data.results.slice0,4.forEachres=>{
html.push`${res.title}`
html.push`${res.url}`
html.push`${res.abstract}`
html.push`${res.published\u date}`
console.logres.multimedia[4].url;
html.push``
}
document.getElementByIdres.innerHTML=html.join
}
在HTML中,图像是用指定图像URL网址的属性定义的:
设html=[];
取回https://api.nytimes.com/svc/topstories/v2/technology.json?api-钥匙
.thenresponse=>response.json
.thendata=>{
//打印getRequest中“response.json”的结果
data.results.slice0,4.forEachres=>{
html.push`${res.title}`
html.push`${res.url}`
html.push`${res.abstract}`
html.push`${res.published\u date}`
console.logres.multimedia[4].url;
html.push``
}
document.getElementByIdres.innerHTML=html.join
}
我认为您需要将src添加到图像中,而不是像这样添加值:
html.push(`<img src='${res.multimedia[4].url}'/>`)
我认为您需要将src添加到图像中,而不是像这样添加值:
html.push(`<img src='${res.multimedia[4].url}'/>`)
您需要分配src属性您需要分配src属性这将不起作用,因为多媒体仍然是响应JSONTANKS中的一个对象,没有看到这一点。这将不起作用,因为多媒体仍然是响应JSONTANKS中的一个对象,没有看到。这不起作用,因为多媒体仍然是响应json中的对象。这不起作用,因为多媒体仍然是响应json中的对象