我有这段代码。
当我运行这个chrome控制台时,它显示'Uncaught TypeError: inviteSection.appendChild is not a function'。请问有没有修复方法,帮帮我!
var inviteSection = document.getElementByClassName("invitedFriends");
var friend = document.createElement("div").class = "friend";
var mail = document.createElement("p").class = "mail";
var span = document.createElement("span").class = "status accepted";
function main() {
inviteSection.appendChild(friend);
friend.appendChild(mail);
friend.appendChild(span);
}
main();
当我运行这个chrome控制台时,它显示'Uncaught TypeError: inviteSection.appendChild is not a function'。请问有没有修复方法,帮帮我!
inviteSection
是一个 NodeList,而不是一个 DOM 元素的引用。 - Arun P JohnygetElementsByClassName
的复数形式。 - Akshay Aroradocument.createElement("p").className = "mail"
。另外,在var mail = document.createElement("p").class = "mail";
这种情况下,变量 mail 的值是字符串"mail"
。这是您想要的吗? - RobG