私は配列とDOMを使用して、配列に格納されている引用符を画面に表示しようとしています。私は出力を得ているので、私は現在、1つのインスタンスでドキュメントオブジェクトモデルを使用していると信じています。しかし、他の例では、画面上に何も表示できません(日付とその日の見積もりは画面に表示されません)。私は見て、私が間違ってやっていることを見つけようと試みましたが、成功しませんでした。これは割り当てのためのもので、DOMを使用する必要があります。だから、ここで私は誰かが正しい方向に私を向けることを望んでいる。どんな提案も大歓迎です。ありがとうございました!DOMを使用して何も表示されない
<html>
<head>
<meta charset="utf-8">
<title>JSJQ Assignment 4 - Arrays/Date Starter File</title>
<style>
body{
font-family: arial, sans-serif;
font-size: 100%;
}
form{
margin-top: 50px;
}
</style>
<script>
//************************************************************
// 1: define variables for today's date,
//************************************************************
var today = new Date();
var day = today.getDate();
var month = today.getMonth();
var year = today.getFullYear();
//************************************************************
// 2: define an array to hold the day names
//************************************************************
var monthArray = new Array();
monthArray[0] = "January";
monthArray[1] = "February";
monthArray[2] = "March";
monthArray[3] = "April";
monthArray[4] = "May";
monthArray[5] = "June";
monthArray[6] = "July";
monthArray[7] = "August";
monthArray[8] = "September";
monthArray[9] = "October";
monthArray[10] = "November";
monthArray[11] = "December";
var dayArray = new Array();
dayArray[0] = "Monday";
dayArray[1] = "Tuesday";
dayArray[2] = "Wednesday";
dayArray[3] = "Thursday";
dayArray[4] = "Friday";
dayArray[5] = "Saturday";
dayArray[6] = "Sunday";
//************************************************************
// 3: define an array to hold the daily quotes
//************************************************************
var quoteArray = new Array();
quoteArray[0] = "Ability is nothing without opportunity - Napoleon Bonaparte";
quoteArray[1] = "Nothing happens unless first we dream - Carl Sandburg";
quoteArray[2] = "Believe you can and you're halfway there - Theodore Roosevelt";
quoteArray[3] = "A place for everything, everything in its place - Benjamin Franklin";
quoteArray[4] = "Don't let the fear of striking out hold you back - Babe Ruth";
quoteArray[5] = "We can't help everyone, but everyone can help someone - Ronald Reagan";
quoteArray[6] = "With self-discipline most anything is possible - Theodore Roosevelt";
//************************************************************
// 4: loop through all of the quotes
// and write the quotes to the page. Use DOM methods or innerHTML
// to write to the page.
//************************************************************
function allQuotes() {
var allQuotes = document.getElementById('quotes');
for (var i = 0; i < quoteArray.length; i++) {
var text = document.createTextNode(quoteArray[i]);
var br = document.createElement('br');
allQuotes.appendChild(text);
allQuotes.appendChild(br);
}
quoteOfTheDay();
}
//************************************************************
// 5: create a window.onload function to format and display
// the current day name.
//
// Display the quote for the day.
//
//
//************************************************************
function quoteOfTheDay() {
document.getElementById('quote_of_the_day').firstChild.nodeValue = quoteArray[today.getDay()-1];
document.getElementById('date').firstChild.nodeValue = dayArray[day] + ", " + monthArray[month] + day + ", " + year;
}
window.onload = allQuotes;
</script>
</head>
<body>
<h1>Quote of the Day</h1>
<p id="quote_of_the_day"></p>
<p id="date"></p>
<h2>All the quotes:</h2>
<p id="quotes"></p>
</body>
</html>
あなたのコードをコピーして保存し、ChromeでHTMLファイルを開いたところです。私はすべての引用符を見ることができる、唯一欠けているのは今日の引用 – Satya
@サティヤです。私は開始の 'ボディ'タグを見つけることができません。 – Sparky256
@MatthewSpireはあなたのスクリプトを置いた後、セクションの本体が終了します。私が何が起こったのか教えてください。 –