gpt4 book ai didi

javascript - 不断收到“无法读取属性错误”

转载 作者:行者123 更新时间:2023-12-01 00:50:38 24 4
gpt4 key购买 nike

不断收到错误消息“Uncaught TypeError: Cannot read property 'style' of null at setDate”不确定我缺少什么!!!

 <script>
const secondHand = document.querySelector('.second-Hand');
const minsHand = document.querySelector('.min-Hand');
const hourHand = document.querySelector('.hour-Hand');

function setDate(){
const now = new Date();

const seconds = now.getSeconds();
const secondsDegrees = ((seconds / 60) * 360) + 90;
secondHand.style.transform = rotate(`${secondsDegrees}deg`);
console.log(seconds);

const mins = now.getMinutes();
const minsDegrees = ((seconds / 60) * 360) + 90;
hourHand.style.transform = `rotate(${minsDegrees}deg)`
}

setInterval(setDate, 1000);

</script>

最佳答案

你的查询选择器可能是错误的。二手也许应该是.二手,你的分钟是错误的,反引号也应该像这样:

secondHand.style.transform = `rotate(${secondsDegrees}deg)`;
const secondHand = document.querySelector('.second-hand');
const minsHand = document.querySelector('.min-hand');
const hourHand = document.querySelector('.hour-hand');

function setDate() {
const now = new Date();

const seconds = now.getSeconds();
const secondsDegrees = ((seconds / 60) * 360) + 90;
secondHand.style.transform = `rotate(${secondsDegrees}deg)`;

const mins = now.getMinutes();
const minsDegrees = ((mins / 60) * 360) + ((seconds/60)*6) + 90;
minsHand.style.transform = `rotate(${minsDegrees}deg)`;
}

setInterval(setDate, 1000);

关于javascript - 不断收到“无法读取属性错误”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57013429/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com