プログラムの説明: - 私のプログラムは、javascript forループを使用して、 "arrays.js"という外部javascript配列のデータをHTMLテーブルに配置します。このプログラムは、 "Date Name Address Amount"の見出しの下に正しいデータを配置するように指定されています。Javascript/forループ/ HTMLテーブルの位置付け
問題: -Theデータ配列は、そのboundarysを逸脱しているか、私はそのは「金額」ヘッダの後に新しいレコードを作成していないテーブルヘッダ「日付名前アドレス額」の中に設定される境界の欠如を言う必要があり、その単純に同じ行に新しいレコードを追加します。 "Date"テーブルヘッダーの下にある次のレコード行に折り返したいと思います。したがって、arryaの日付の値は、「日付」ヘッダー、「Name」ヘッダーの下の名前の値などになります。例次のように.... 例:4つのヘッダー(日付、名前、住所、金額)私は次の配列の次の日付の開始を "日付"テーブルheader.Itの下に置くことを望んでいます。新しいレコードの行に折り返さない同じ行に配列の次の日付の値を置きます。コードは以下の通りです。
index.htmlを
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Winch - Lab 10</title>
<script src="arrays.js" type="text/javascript"></script>
<script type="text/javascript">
function totalContributions()
{
var totalAmount = 0;
for (var i = 0; i < amount.length; i++)
totalAmount = totalAmount + amount[i];
return totalAmount;
}
</script>
</head>
<body>
<table id="donations">
<tr>
<th>Date</th>
<th>Name</th>
<th>Address</th>
<th>Amount</th>
</tr>
<script>
for (var x=0; x < amount.length; x++){
if (x%2==0){
document.write("<tr>");
} else {
document.write("<tr class='stripe'>");
}
document.write("<td>"+date[x]+"</td>");
document.write("<td>"+firstName[x]+" "+lastName[x]+"</td>");
document.write("<td>"+street[x]+"<br>"+city[x]+","+state[x]+" "+zip[x]);
document.write("<td class='amt'>$"+amount[x]+"</td>");
document.write("</tr)");
}
</script>
</table>
</body>
</html>
**arrays.js**
street = new Array();
city = new Array();
state= new Array();
zip = new Array();
amount = new Array();
date = new Array();
firstName[0]="Ron";
lastName[0]="Burgundy";
street[0]="88 Regal Lane";
city[0]="Williamsburg";
state[0]="KY";
zip[0]="40769";
amount[0]=625;
date[0]="2015-07-18";
firstName[1]="Ricky";
lastName[1]="Bobby";
street[1]="407 Easy Street";
city[1]="London";
state[1]="KY";
zip[1]="40744";
amount[1]=75;
date[1]="2015-07-18";
firstName[2]="Veronica";
lastName[2]="Corningstone";
street[2]="743 Stawlings Drive";
city[2]="Danville";
state[2]="KY";
zip[2]="40423";
amount[2]=50;
date[2]="2015-07-16";
firstName[3]="Brick";
lastName[3]="Tamland";
street[3]="102 Maple Lane";
city[3]="Danville";
state[3]="KY";
zip[3]="40423";
amount[3]=150;
date[3]="2015-07-15";
変更されたdocument.write( " tr)"); to document.write( ""); **コードは今、私はstackoverflowの新しい答えを投票しようとしましたが、私はそうするenofポイントがありません?私はポイントを受け取ったときに戻ってきます。ありがとう "コア"私はあなたに報いるために戻ってきます。 –
@EdwardWinch問題はない、私はそれがあなたを助けてうれしい。:) –