尝试添加 HTML 节点但它没有出现
我有以下 javascript 函数:
function addConfirmLine(number, strItem, strValue) {
var confirmLine = document.getElementById("divConfirmation").appendChild(document.createElement("div"));
confirmLine.id = "divConfirmLine" + number;
var confirmItem = confirmLine.appendChild(document.createElement("div"));
confirmItem.className = "confirmItem";
confirmItem.nodeValue = strItem;
var confirmValue = confirmLine.appendChild(document.createElement("div"));
confirmValue.className = "confirmValue";
confirmValue.nodeValue = strValue;
}
和一个像这样的 div
<div id="divConfirmation">
<div class="checkHead">
Check the following details. Click "Prev" to make corrections. Click "Upload" to process and upload the sermon.
</div>
</div>
目的是最终得到这样的结果:
<div id="divConfirmation">
<div class="checkHead">
Check the following details. Click "Prev" to make corrections. Click "Upload" to process and upload the sermon.
</div>
<div id="divConfirmLine1">
<div class="confirmItem">Item1</div>
<div class="confirmValue">Value1</div>
</div>
<div id="divConfirmLine2">
<div class="confirmItem">Item2</div>
<div class="confirmValue">Value2</div>
</div>
</div>
问题是它不起作用。新的 div
没有出现,并且我没有收到任何错误。我做错了什么?
I've got the following javascript function:
function addConfirmLine(number, strItem, strValue) {
var confirmLine = document.getElementById("divConfirmation").appendChild(document.createElement("div"));
confirmLine.id = "divConfirmLine" + number;
var confirmItem = confirmLine.appendChild(document.createElement("div"));
confirmItem.className = "confirmItem";
confirmItem.nodeValue = strItem;
var confirmValue = confirmLine.appendChild(document.createElement("div"));
confirmValue.className = "confirmValue";
confirmValue.nodeValue = strValue;
}
and a div
like this
<div id="divConfirmation">
<div class="checkHead">
Check the following details. Click "Prev" to make corrections. Click "Upload" to process and upload the sermon.
</div>
</div>
The intent is to end up with something like this:
<div id="divConfirmation">
<div class="checkHead">
Check the following details. Click "Prev" to make corrections. Click "Upload" to process and upload the sermon.
</div>
<div id="divConfirmLine1">
<div class="confirmItem">Item1</div>
<div class="confirmValue">Value1</div>
</div>
<div id="divConfirmLine2">
<div class="confirmItem">Item2</div>
<div class="confirmValue">Value2</div>
</div>
</div>
Problem is it doesn't work. The new div
s don't appear, and I don't get any errors. What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
元素的 nodeValue 始终为 null。您想要添加文本节点:
The nodeValue of an Element is always null. You want to add text nodes: