如何使用 JavaScript 将另一个文本放入单元格中?



我想将数组价格放在数组开胃菜的同一单元格中。我也试过了,但我替换了文本。我想将所有两个数组都放在同一个单元格中。 我不知道该怎么做。有人可以告诉我怎么做吗?非常感谢

这是图片: https://i.stack.imgur.com/qwOkj.png

function generateTableAntipasti() {
//Build an array containing Customer records.
var antipasti = new Array();
antipasti.push(["Antipasti"]);
antipasti.push(["Patatine"]);
antipasti.push(["Kellogs"]);
antipasti.push(["Ciao"]);
antipasti.push(["Hello"]);
antipasti.push(["Bye"]);
var price = new Array();
price.push(["5,00$"]);
price.push(["5,00$"]);
price.push(["5,00$"]);
price.push(["5,00$"]);
price.push(["5,00$"]);
price.push(["5,00$"]);

//Create a HTML Table element.
var table = document.createElement("Table");
table.border = "1";
table.className = "Antipasti";
table.cellSpacing = 20;
//Add the data rows.
for (var i = 0; i < antipasti.length; i++) {
row = table.insertRow(-1);
var cell = row.insertCell(-1);
cell.innerHTML = antipasti[i];     
}
var dvTable = document.getElementById("dvTable");
dvTable.innerHTML = "";
dvTable.appendChild(table);
}

以上所有要点放在一起并缩短了一点......

function generateTableAntipasti() {
//Build an array containing Customer records.
var antipasti = ["Antipasti","Patatine","Kellogs","Ciao","Hello","Bye"], 
price =     ["5,00$","5,00$","5,00$","5,00$","5,00$","5,00$"];
//Create a HTML Table element.
var table = document.createElement("Table");
table.border = "1";
table.className = "Antipasti";
table.cellSpacing = 8;
//Add the data rows.
antipasti.forEach((a,i)=>table.insertRow(-1).insertCell(-1).innerHTML = a +'<br>'+price[i]);
var dvTable = document.getElementById("dvTable");
dvTable.innerHTML = "";
dvTable.appendChild(table);
}
generateTableAntipasti()
<div id="dvTable"></div>

相关内容

  • 没有找到相关文章

最新更新