word
オブジェクトの新しい各インスタンス内からのみ取得しようとしていnewEntry
ます。新しい単語を追加するたびにコンソールに表示されますが、に割り当てると表示されません.innerHTML
。誰でも助けることができますか?
完全なコード:
<style type="text/css" media="screen">
#output { height: auto;}
</style>
<script type="text/javascript">
// Array to contain words
var wordList = Array();
// word list constructor
function addWord(word) {
this.word = word;
this.description = "a description of the word";
this.entryDate = "01.02.2012";
this.userName = "John Doe";
var newEntry = {
word: word,
description: description,
entryDate: entryDate,
userName: userName
};
wordList[wordList.length] = newEntry;
};
// collect data from form
function getFormData() {
var results = document.getElementById("textbox").value;
addWord(results);
var data = '<ul>';
var numObjects = "Number of words = " + wordList.length;
for (var x in wordList) {
var wordSet = wordList[x];
for (var item in wordSet.word[x]) {
console.log(wordSet.word);
data += "<li><a href='#'>" + wordSet.word + "</a></li>";
};
};
data += "</ul>";
document.getElementById("Objects").innerHTML = numObjects;
document.getElementById("Output").innerHTML = data;
// console.log(wordList);
};
</script>
</head>
<body>
<form id="form_id" name="form_name" action="" method="post">
<p><label for="text">Enter words:<br/></label>
<input type="textarea" id="textbox" />
<input type="button" value="Go" onclick="getFormData()"
</form>
<ul id="Output"></ul>
<div id="Objects"></div>
</body>