gpt4 book ai didi

javascript - 表 - 循环和数组

转载 作者:行者123 更新时间:2023-12-03 07:03:29 25 4
gpt4 key购买 nike

我正在创建一个如下所示的表格,但无法将我的信息放入正确的列/行中。任何帮助将非常感激!谢谢!

enter image description here

我的代码是:

        //data provided by HomewareCity for shopping catalogue      
var productListArr = new Array('Salad Server Set', 'Party Serviette Holder',
'Tea Set', 'Mixing Bowl Set', 'Knife Block Set', 'Coffee Capsule Holder',
'Plastic Sensor Soap Pump', 'Storage Bucket', 'Oven Glove', 'Apron',
'Biscuit Barrel', 'Chopping Board', 'Carioca Cups', 'Soup Bowls',
'Elevate Wood Turner', 'Pasta Machine', 'Teapot', 'Cake Pop Scoop',
'Cookbook Stand', 'Chocolate Station', 'Coffee Maker', 'Pepper Mill',
'Salt Mill', 'Glass Storage Jar', 'Measuring jug', 'Kitchen Scale',
'Tenderiser', 'Pizza Docker', 'Knife Sharpener', 'Steel Cork Opener',
'Steel Garlic Press', 'Steel Can Opener',
'Stainless Steel Crank Flour Sifter', 'Mineral Stone Mortar and Pestle',
'Citrus Cather', 'Cherry & Olive Pitter', 'Multi Grater-Detachable',
'Stainless Steel Colander', 'Steel Pizza Pan', 'Pop Container');
var priceListArr = new Array(18.70, 11.95, 39.95, 49.95, 99.95, 29.95, 79.95, 24.95,
9.95, 29.95, 39.95, 12.95, 54.95, 43.00, 19.95, 144.95, 29.95, 9.95,
29.95, 34.95, 29.00, 84.94, 84.95, 4.95, 19.95, 39.95, 34.95, 19.95,
79.95, 36.95, 34.95, 36.95, 33.95, 74.95, 19.95, 27.95, 26.95, 44.95,
12.95, 22.95);
var orderedProductCodeArr = new Array [];
var quantityArr = new Array ();
document.write('<table width="80%" height="150px" cellpadding="2px" cellspacing="3px" border="1">');
for(var i=0; i<orderedProductCodeArr.length; i++)

document.write('<tr><th>Code</th></tr')
document.write('<tr><th>Product</th></tr');
document.write('<tr><th>Price</th></tr')

{
document.write('<tr><td>' + orderedProductCodeArr[i] + '</td></tr>');
}
document.write('</table')
for(var i=0; i<priceListArr.length; i++)
{
document.write('<tr><td>' + priceListArr[i] + '</td></tr>');
}
document.write('</table')

最佳答案

像这样吗?

var productListArr = new Array('Salad Server Set', 'Party Serviette Holder', 
'Tea Set', 'Mixing Bowl Set', 'Knife Block Set', 'Coffee Capsule Holder',
'Plastic Sensor Soap Pump', 'Storage Bucket', 'Oven Glove', 'Apron',
'Biscuit Barrel', 'Chopping Board', 'Carioca Cups', 'Soup Bowls',
'Elevate Wood Turner', 'Pasta Machine', 'Teapot', 'Cake Pop Scoop',
'Cookbook Stand', 'Chocolate Station', 'Coffee Maker', 'Pepper Mill',
'Salt Mill', 'Glass Storage Jar', 'Measuring jug', 'Kitchen Scale',
'Tenderiser', 'Pizza Docker', 'Knife Sharpener', 'Steel Cork Opener',
'Steel Garlic Press', 'Steel Can Opener',
'Stainless Steel Crank Flour Sifter', 'Mineral Stone Mortar and Pestle',
'Citrus Cather', 'Cherry & Olive Pitter', 'Multi Grater-Detachable',
'Stainless Steel Colander', 'Steel Pizza Pan', 'Pop Container');
var priceListArr = new Array(18.70, 11.95, 39.95, 49.95, 99.95, 29.95, 79.95, 24.95,
9.95, 29.95, 39.95, 12.95, 54.95, 43.00, 19.95, 144.95, 29.95, 9.95,
29.95, 34.95, 29.00, 84.94, 84.95, 4.95, 19.95, 39.95, 34.95, 19.95,
79.95, 36.95, 34.95, 36.95, 33.95, 74.95, 19.95, 27.95, 26.95, 44.95,
12.95, 22.95);
var orderedProductCodeArr = new Array ();
var quantityArr = new Array ();
document.write('<table width="80%" height="150px" cellpadding="2px" cellspacing="3px" border="1">');
document.write('<th>Code</th>');
document.write('<th>Product</th>');
document.write('<th>Price</th>');
for(var i=0; i<productListArr.length; i++){

document.write('<tr><td>' + i + '</td>');
document.write('<td>' + productListArr[i] + '</td>');
document.write('<td>' + priceListArr[i] + '</td></tr>');
}
document.write('</table>');

关于javascript - 表 - 循环和数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36929563/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com