【问题标题】:Why are those quotations there and how can I remove them?为什么这些引号在那里,我该如何删除它们?
【发布时间】:2019-02-04 21:07:06
【问题描述】:

当我运行以下代码时:

const root = document.querySelector('#root3');

async function fetchData(userId) {
  const response = await fetch(`https://randomuser.me/api/?results=10`);
  const data = await response.json();
  console.log(data);
  console.log(data.results);
  data.results.map(item => {
    root.append(`<li><img src=${item.picture.thumbnail}></li>`);
  });
}

fetchData();

结果是这样的:

为什么会有这些引文?我怎样才能摆脱它们?

【问题讨论】:

  • Java != JavaScript
  • 您不是“附加元素”,而是“附加字符串”。我想您可能正在寻找类似 @​​987654324@ 的东西,其中一些 HTML 被添加到现有元素中。

标签: javascript fetch quotations


【解决方案1】:

好的。您不能在 JavaScript 中使用 append。 一种可行的解决方案如下:

root.innerHTML += `<li><img src=${item.picture.thumbnail}></li>`;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-10-15
    • 1970-01-01
    • 2016-08-24
    • 2020-04-27
    • 2012-05-30
    • 2021-07-12
    • 1970-01-01
    • 2010-11-10
    相关资源
    最近更新 更多