我仅在每次用户单击字母时尝试遍历字符串。
如果用户单击字符串上的字母。该字母应显示在屏幕上,但我的代码有问题,特别是在事件处理程序上。有什么建议么?
var view = {
displayMessage : function (msg) {
var messageArea = document.getElementById ("messageArea");
messageArea.innerHTML = msg;
},
displayWord : function (word) {
var areaword = document.getElementById ("word");
areaword.innerHTML = word;
},
};
window.onload = init;
var newWord = "quizzes";
function init () {
var buttons = document.getElementsByTagName ("input");
for (var i = 0; i < buttons.length; i++) {
buttons[i].onclick = showLetter;
}
}
function showLetter (eventObj) {
var value = eventObj.target.value;
for (var i = 0; i < newWord.length; i++) {
if (newWord.charAt (i) == = value) {
view.displayMessage (value);
}
}
}