怎么编写javascript代码使网页在客户端显示为白天字体黑色背景白色而在晚上字体黑色背景白色?

来源:百度知道 编辑:UC知道 时间:2024/06/06 02:32:31
让浏览网页得人在白天和黑夜看到不同得效果

以晚上6点为分隔,以24小时制为准,但如果客户端是以12小制的,还没想好怎么判断。

<script>
var newtime=new Date();
var userbg=newtime.getHours();
if(userbg<18){
document.body.style.background="#ffffff";
document.body.style.color="#000000";
}
else{
document.body.style.background="#000000";
document.body.style.color="#ffffff";
}
</script>

取得系统时间,看看几点,然后做