![](/img/trans.png)
[英]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
[英]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?
試過這樣的東西potterCharacters.forEach((x) => getCharacters(x.name));
這僅顯示名稱,但似乎無法繼續。
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:
<table id="characters"></table>
嘗試過類似potterCharacters.forEach((x) => getCharacters(x.name));
這僅顯示名稱,但似乎無法繼續使用。
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.