如何使用 DOM getElementById 返回数组

问题描述 投票:0回答:1

code.js(js文件)

 let winter = ["applle","orange","grape"];
 console.log(winter);
document.getElementById("fruits").innerHTML = winter;
<h1 id="fruits">fruit stall</h1>

为什么它对我不起作用,有人可以帮忙吗......

我希望数组元素作为输出而不是“水果摊”

javascript arrays dom getelementbyid
1个回答
0
投票

您的代码完美运行:

let winter = ["applle", "orange", "grape"];
console.log(winter);
document.getElementById("fruits").innerHTML = winter;
<h1 id="fruits"> fruit stall</h1>

© www.soinside.com 2019 - 2024. All rights reserved.