菜鸟问题提醒!我正在研究一个每秒更新的基本时钟,但它没有更新,因为我收到未捕获错误:NOT_FOUND_ERR:DOM Exception 8。基本上我只需将函数末尾的 removeChild() 更改为其他内容,但我不知道改成什么。我想删除<p class="time">
正在创建的。
function spitTime() {
var clock = new Date();
var hours = clock.getHours();
var minutes = clock.getMinutes();
var seconds = clock.getSeconds();
if (minutes <= 9) {
minutes = "0" + minutes;
}
if (seconds <= 9) {
seconds = "0" + seconds;
}
var displayTime = hours + ":" + minutes + ":" + seconds;
var newTimeElem = document.createElement("p");
newTimeElem.className = "time";
var timeText = document.createTextNode(displayTime);
newTimeElem.appendChild(timeText);
document.getElementById("timePlace").appendChild(newTimeElem);
document.getElementById("timePlace").removeChild();
}
相关HTML:
<div class="clock">
<span id="timePlace"></span>
</div>