我正在尝试使用javascript在晚上9点到10点之间更改文本阴影的方向。
尝试了许多更改,但不确定我哪里出错了,这是我代码的基础知识。
<head>
<style>
body {
text-shadow: 12px 12px 8px #000000;
}
</style>
<script>
var currentTime = new Date().getHours();
if (21 <= currentTime && currentTime < 22)
{
document.getElementById('body').text.style.textShadow = "-12px 12px 8px
#000000";
}
</script>
</head>
.. 没有包含正文,但我的文本<在div class="..."> <,并且 href="...">这是否有帮助? 在div>
所以通常文本阴影应该在右边,晚上 9 点到 10 点之间应该在左边?
谢谢!
根据评论,我认为这是错误的:
document.getElementById('body').text
要阐明的示例代码段:
document.addEventListener('DOMContentLoaded', function(e) {
document.querySelector('button').addEventListener('click', function(e) {
document.querySelectorAll('div, a').forEach(function(ele) {
ele.style.textShadow = "-12px 12px 8px #000000";
});
})
});
body {
text-shadow: 12px 12px 8px #000000;
}
<div>
this is a text iside a div......
</div>
<a href="">this is a text inside an anchor......</a>
<br/>
<br/>
<button type="button">Click Me</button>