0
我已經構建了一個簡單的程序來學習Javascript中的OOP。它只輸出預定義的字符串語句。這裏的問題是程序將文本節點直接綁定到「輸出div」,而忽略了前面的命令將它們附加到相應的「p」元素。document.createElement()被忽略
Student.prototype.sayHello = function()
{
var responseString = document.createTextNode("Hello, I've been waiting here for you. Student.");
return document.createElement("p").appendChild(responseString);
}
Student.prototype.sayGoodBye = function()
{
var responseString = document.createTextNode("tchau");
return document.createElement("p").appendChild(responseString);
}
var student = new Student();
document.getElementById("output").appendChild(student.sayHello());
document.getElementById("output").appendChild(student.walk());
document.getElementById("output").appendChild(student.sayGoodBye());