我需要输出从左到右读取的多列表。表格图片显示了刚开始的几个玩具的外观。我必须使用DOM节点输出表。我还需要在“代码”列中生成一个顺序的代码号。我一直在为此绞尽脑汁,所以任何帮助将不胜感激。
var productsArr = new Array('ToyA', 'ToyB', 'ToyC', 'ToyD', 'ToyE', 'ToyF', 'ToyG', 'ToyH');
var pricesArr = new Array(18.70, 11.95, 39.95, 49.95, 54.65, 32.10, 18.70, 11.95);
for (var i = 0; i < productsArr.length; i++) {
document.writeln('<table border="1">');
document.writeln('<tr>');
document.writeln('<th>Code</th>');
document.writeln('<th>Product</th>');
document.writeln('<th>Price</th>');
document.writeln('</tr>');
document.writeln('<tr>');
document.write("<td>Generate Number</td>" + "<td>" + productsArr[i] + "</td>" + "<td>" + pricesArr[i] + "</td>")
document.writeln('</tr>');
document.writeln('</table>');
}
最佳答案
根据您的ID或编号,这是随机的...
document.write(
"<td>" + Math.floor(Math.random() * 10000000) + "</td>" +
"<td>" + productsArr[i] + "</td>" +
"<td>" + pricesArr[i] + "</td>"
);
这是顺序的...
document.write(
"<td>" + i + "</td>" +
"<td>" + productsArr[i] + "</td>" +
"<td>" + pricesArr[i] + "</td>"
);