0

所以我试图将我的日期从JS文件中的函数传递到我html的网页中。出于某种原因,我不断收到错误消息 /* Exception: Node cannot be inserted at the specified point in the hierarchy @42 */

帮助将不胜感激。这是我的代码。

function time() {       //function to add date/time stamp to the footer of the html document


var timestamp=document.getElementById("time");
var timecreation=document.createTextNode("p");
var d = new Date();
var timetextnode=document.createTextNode(d);

timecreation.appendChild(timetextnode);
timestamp.appendChild(timecreation);

}

time();

HTML

<hr size="2" width="100%">
<footer id = "time">
<p> Michael Longo web site, July 2013 </p>
</footer>
4

1 回答 1

0
var timecreation=document.createTextNode("p");

应该

var timecreation=document.createElement("p");

您不能附加到文本节点。

JSFiddle 演示

于 2013-07-17T05:17:41.290 回答