简体   繁体   English

我有一个字符数组,我想使用 javascript 在 html 中以 4 行的形式显示名称、房屋和图像。 我是foreach吗?

[英]I have a array of characters, I want to display the name, house and image in rows of 4 in html using javascript. Do I foreach?

tried something like this potterCharacters.forEach((x) => getCharacters(x.name));试过这样的东西potterCharacters.forEach((x) => getCharacters(x.name)); This displays the name only but cant seem to go on with it.这仅显示名称,但似乎无法继续。

function Init()
{
    debugger;
    potterCharacters.forEach((x) => getCharacters(x.name));
    text += "</ul>";
    document.getElementById("rows").innerHTML = text;    
}

function getCharacters(value)
{
    text += "<th>" + value + "</th>";
}```
function Init() {
    const text = potterCharacters.map(character => {
        const { name, house, image } = character
        return `<tr>
            <td>${name}</td>
            <td>${house}</td>
            <td><img src="${image}"/></td>
        </tr>`
    })
    document.getElementById("characters").innerHTML = text    
}

html: html:

<table id="characters"></table>

tried something like this potterCharacters.forEach((x) => getCharacters(x.name));尝试过类似potterCharacters.forEach((x) => getCharacters(x.name)); This displays the name only but cant seem to go on with it.这仅显示名称,但似乎无法继续使用。

function Init()
{
    debugger;
    potterCharacters.forEach((x) => getCharacters(x.name));
    text += "</ul>";
    document.getElementById("rows").innerHTML = text;    
}

function getCharacters(value)
{
    text += "<th>" + value + "</th>";
}```

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我有7张图片。 我想使用javascript向不同的用户随机显示不同的图像。 但是一旦显示,它就不会改变 - I have 7 images. I want to display different images to different users randomly using javascript. But once it is displayed, it should not change 我希望行在 JavaScript 中按类型排列。 可能吗? - I want rows to column with type wise in JavaScript. is it possible? 我有一个从 CSV 转换为 JavaScript 的 HTML 表。我想向第二列中的行添加超链接。 请帮我 - I have a HTML table converted from CSV with JavaScript. I want to add hyperlinks to the rows in the 2nd column. Please help me 我想使用Jquery或Javascript检索XML节点。 节点包含表单的HTML - I want to retrive XML node using Jquery or Javascript. Node contains HTML of a form 我想使用JavaScript在点击图片(上下箭头.PNG)时增加和减少数量标签文本。 - I want to increase and decrease quantity label text on click on image (up down arrow .PNG) using JavaScript. 我有一个JavaScript数组,我想下载数组中的每个图像 - I have a JavaScript array and I want to download each image in the array 我下载了一个文本文件。 我不想下载,而是想使用 javascript 在 html 页面中显示它 - I have downloaded a text file. Instead of downloading I want to display it in a html page using javascript 我正在使用 javascript 创建一个待办事项列表。 我想让它在选中/取消选中复选框时添加/删除 class - I am creating a to do list using javascript. I want to make it so that when the check box is check/unchecked it adds/removes a class 我用javascript生成了html代码(很多div)。 现在我想用GetElementById查找生成的div - I generated html code (lots of divs) with javascript. Now I want to find the generated divs with GetElementById 如何使用javascript从网站提取数据。 - How do I extract data from a website using javascript.
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM