cuốn sách gpt4 ai đã làm

javascript - 尝试更改 innerHTML 时出错 - 无法设置 null 的属性 'innerHTML'

In lại Tác giả: Walker 123 更新时间:2023-11-28 17:51:47 27 4
mua khóa gpt4 Nike

我正在尝试根据 javascript 函数填充的数字更改 div 的innerHTML。不幸的是,我收到了一个错误,但我不确定为什么。

伪代码

nếu nhưnumber > 2将innerHTML更改为,否则更改为.

我环顾四周,发现了一些与在 DOM 之前触发的函数相关的内容。我做了一些改变,但仍然没有成功。我做错了什么?如何在 DOM 渲染后触发该函数? window.onload 不是已经在做这项工作了吗?

提前谢谢

JS

$(document).ready(function() {
window.onload = function() {
// Month,Day,Year,Hour,Minute,Second
upTime('may,05,2006,00:00:00');
};

function upTime(countTo) {
var now = new Date();
countTo = new Date(countTo);
var difference = (now - countTo);

var years = Math.floor(difference / (60 * 60 * 1000 * 24) / 365);
var days = Math.floor(difference / (60 * 60 * 1000 * 24) * 1);
var hours = Math.floor((difference % (60 * 60 * 1000 * 24)) / (60 * 60 * 1000) * 1);
var mins = Math.floor(((difference % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) / (60 * 1000) * 1);
var secs = Math.floor((((difference % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) % (60 * 1000)) / 1000 * 1);

document.getElementById('years').firstChild.nodeValue = years;
document.getElementById('days').firstChild.nodeValue = days;
document.getElementById('hours').firstChild.nodeValue = hours;
document.getElementById('minutes').firstChild.nodeValue = mins;
document.getElementById('seconds').firstChild.nodeValue = secs;

if (secs > 2) {
console.log('over');
document.getElementById('.seconds').innerHTML = "seconds";
} khác {
console.log('lower');
document.getElementById('.seconds').innerHTML = "second";
}

clearTimeout(upTime.to);
upTime.to = setTimeout(function() {
upTime(countTo);
}, 1000);
}
});

câu trả lời hay nhất

class获取元素:document.getElementsByClassName('seconds') 和按Id document.getElementById('seconds') )

但是对于 jQuery,NHẬN DẠNG $('#seconds')class $('.seconds')

关于javascript - 尝试更改 innerHTML 时出错 - 无法设置 null 的属性 'innerHTML',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45376760/

27 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress