每当我单击某个字母时,我希望value
从头开始的第一个插槽更改为value
我单击的字母。我将它letter.onclick = letterClick(this);
放入for
循环中是否正确,或者我应该以其他方式实现它。另外,letterClick()
函数应该包含什么?
// Makes slots and letters for the chosen word.
function maker() {
for (i=0; i<word.length; i++) {
var slot = document.createElement("input");
var letter = document.createElement("input");
var letters=(shuffledWord).split("");
slot.type = "submit";
slot.value = "";
slot.id = "slot" + i;
slot.setAttribute('id', 'slot');
letter.type = "submit";
letter.value = letters[i];
letter.id = "letter" + i;
letter.onclick = letterClick(this);
letter.setAttribute('id', 'letter');
document.getElementById("slotbar").appendChild(slot);
document.getElementById("letterbar").appendChild(letter);
}
}