gpt4 book ai didi

javascript - 无法将appendchild函数添加到对象中的属性

转载 作者:行者123 更新时间:2023-12-03 08:02:37 25 4
gpt4 key购买 nike

<!DOCTYPE html>
<html>
<body>
<script text="type/javascript">
var countdown=function()
{
// create a couple of elements in an otherwise empty HTML page
this .heading=document.createElement("h1");
this .heading_text=document.createTextNode("Big Head!");
this .heading.appendChild(heading_text);
this .document.body.appendChild(heading);
}
var obj1 = new countdown();
</script>
</body>
</html>

在上面的代码中,我无法将appendChild(heading_text)添加到heading_text属性并面临错误

"Uncaught ReferenceError: heading_text is not defined".

如何继续该计划?

最佳答案

因为 this.heading_text 存在,而 heading_text 不存在

成功

var countdown=function()
{
// create a couple of elements in an otherwise empty HTML page
var heading=document.createElement("h1");
var heading_text=document.createTextNode("Big Head!");
heading.appendChild(heading_text);
document.body.appendChild(heading);
}

关于javascript - 无法将appendchild函数添加到对象中的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34528843/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com