你问题在于以下几点:
var dwarfButton = chatbox.appendChild(document.createElement("button")).textContent = "DWARF"; dwarfButton.setAttribute("id", "dwarf");
你在这里有一些链接,但最终你将dwarfButton
变量设置为字符串"DWARF"
,而不是你创建的DOM元素.
试试这个:
var dwarfButton = document.createElement("button"); dwarfButton.textContent = "DWARF"; dwarfButton.setAttribute("id", "dwarf"); chatbox.appendChild(dwarfButton);