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

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

無(wú)法從紐約時(shí)報(bào) API 檢索數(shù)據(jù)

無(wú)法從紐約時(shí)報(bào) API 檢索數(shù)據(jù)

縹緲止盈 2021-11-12 17:24:44
我試圖獲得最大的image,title,short description和url來(lái)自紐約時(shí)報(bào)API頭條新聞。在獲得我需要的所有信息之前,我試圖只獲得標(biāo)題,但似乎無(wú)法獲得任何信息。我的代碼有問(wèn)題嗎?更新:我已將元素添加到 DOM(請(qǐng)參閱下面的代碼),但標(biāo)題仍未顯示。我之前也嘗試在控制臺(tái)中打印它,但那里也沒(méi)有打印任何內(nèi)容。var url = 'https://api.nytimes.com/svc/topstories/v2/science.json?api-key=MY_API_KEY'function setup() {    noCanvas()    loadJSON(url, gotData)}function gotData(data) {const articles = data.resultsfor (let i = 0; i < articles.length; i++) {    const title = document.createElement('h1')     title.innerText = articles[i].title     document.body.appendChild(title)}}
查看完整描述

2 回答

?
慕少森

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

好吧,您創(chuàng)建了元素,但您仍然需要將它添加到 DOM。


要?jiǎng)?chuàng)建您的元素:


const title = document.createElement('h1')


并將其添加到 DOM(使其實(shí)際出現(xiàn)在您的頁(yè)面上):


document.body.appendChild(title)


但是現(xiàn)在您仍然需要從 API 中添加您的實(shí)際標(biāo)題:


title.innerText = articles[i].title


一起來(lái):


const title = document.createElement('h1') // create the heading

title.innerText = articles[i].title // add the title from the API to your heading

document.body.appendChild(title) // add your heading to the DOM (this will make it appear)



查看完整回答
反對(duì) 回復(fù) 2021-11-12
?
有只小跳蛙

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

看看這個(gè)。我回答了你的騙局,但這里更好


let html = [];

fetch('https://api.nytimes.com/svc/topstories/v2/science.json?api-key=yourApiKey')

  .then((resp) => resp.json())

  .then(function(data) {

    data.results.forEach(res => {

      html.push(`<h1>${res.title}</h1>`);

    })

    document.getElementById("res").innerHTML = html.join("");

  })

<div id="res"></div>


查看完整回答
反對(duì) 回復(fù) 2021-11-12
  • 2 回答
  • 0 關(guān)注
  • 167 瀏覽
慕課專欄
更多

添加回答

舉報(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)