【发布时间】:2015-06-23 04:50:08
【问题描述】:
我正在尝试将我的 HTML 文档中的 p 替换为用 Javascript 创建的段落。页面加载后,two 将替换为 t。
var two = document.getElementById("two");
document.onload = function myFunction() {
var p = document.createElement("p");
var t = document.createTextNode("I am the superior text");
p.appendChild(t);
document.getElementById("p");
document.two = p;
};
【问题讨论】:
-
您不使用 jquery 有什么原因吗?而且为什么不直接替换
p这一段的内容呢?
标签: javascript function onload getelementbyid appendchild