如何解决错误 => "Cannot set properties of null (setting 'innerHTML')"?
How do I solve error => "Cannot set properties of null (setting 'innerHTML')"?
https://codepen.io/bSwastik6/pen/QWQgYPO?editors=1010
JAVASCRIPT 代码存在一些我无法解决的问题。如果你们检查代码中的错误,将会有所帮助。
错误:{未捕获的类型错误:无法设置 null 的属性(设置 'innerHTML')}
// Variables
var tenspart = 0;
var minpart = 0;
var secpart = 0;
var time;
// Node Selector
var start = document.querySelector(".start");
var stop = document.querySelector(".stop");
var reset = document.querySelector(".reset");
var tenth = document.querySelector(".tens");
var minute = document.querySelector(".min");
var second = document.querySelector(".second");
// Add Event Listener
start.addEventListener("click", () => {
clearInterval(time);
time = setInterval(watchCounter, 10);
});
stop.addEventListener("click", () => {
clearInterval(time);
});
reset.addEventListener("click", () => {
clearInterval(time);
tenspart = 0;
minpart = 0;
secpart = 0;
tenth.innerHTML = "0" + tenspart;
second.innerHTML = "0" + secpart;
minute.innerHTML = "0" + minpart;
});
// Event Function
var watchCounter = function () {
tenspart++;
tenth.innerHTML = tenspart;
if (tenspart < 9) {
tenth.innerHTML = "0" + tenspart;
}
if (tenspart > 99) {
secpart++;
second.innerHTML = secpart;
if (secpart < 9) {
second.innerHTML = "0" + secpart;
}
tenspart = 0;
}
if (secpart > 59) {
minpart++;
minute.innerHTML = minpart;
if (minpart < 9) {
minute.innerHTML = "0" + minpart;
}
secpart = 0;
}
};
您的 class 秒名称 div 是“sec”,但您的目标是 JavaScript.
中的“.second”
https://codepen.io/bSwastik6/pen/QWQgYPO?editors=1010
JAVASCRIPT 代码存在一些我无法解决的问题。如果你们检查代码中的错误,将会有所帮助。
错误:{未捕获的类型错误:无法设置 null 的属性(设置 'innerHTML')}
// Variables
var tenspart = 0;
var minpart = 0;
var secpart = 0;
var time;
// Node Selector
var start = document.querySelector(".start");
var stop = document.querySelector(".stop");
var reset = document.querySelector(".reset");
var tenth = document.querySelector(".tens");
var minute = document.querySelector(".min");
var second = document.querySelector(".second");
// Add Event Listener
start.addEventListener("click", () => {
clearInterval(time);
time = setInterval(watchCounter, 10);
});
stop.addEventListener("click", () => {
clearInterval(time);
});
reset.addEventListener("click", () => {
clearInterval(time);
tenspart = 0;
minpart = 0;
secpart = 0;
tenth.innerHTML = "0" + tenspart;
second.innerHTML = "0" + secpart;
minute.innerHTML = "0" + minpart;
});
// Event Function
var watchCounter = function () {
tenspart++;
tenth.innerHTML = tenspart;
if (tenspart < 9) {
tenth.innerHTML = "0" + tenspart;
}
if (tenspart > 99) {
secpart++;
second.innerHTML = secpart;
if (secpart < 9) {
second.innerHTML = "0" + secpart;
}
tenspart = 0;
}
if (secpart > 59) {
minpart++;
minute.innerHTML = minpart;
if (minpart < 9) {
minute.innerHTML = "0" + minpart;
}
secpart = 0;
}
};
您的 class 秒名称 div 是“sec”,但您的目标是 JavaScript.
中的“.second”