<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>時間事件</title>
</head>
<body>
</body>
<script>
var int_time=new Date();//使用Date獲取網絡時間;
function title(){
var sys_time= int_time.getHours();//這里只需要整點時間,所以我提取的是"時";
console.log(typeof?sys_time)//可以輸出變量名看出來,這個變量是Number類型;
if(sys_time>0&&sys_time<=6){
alert("再睡會就天亮了");
}? if(sys_time>6&&sys_time<12){
alert('堅持一下,要吃午飯了');
}if(sys_time>=12&&sys_time<18){
alert('午飯已經吃過了,晚飯還遠嗎?');
}if(sys_time>=18&&sys_time<=23){
alert('忙了一天,放松一下,可以做一下愛做的事了');
}
}
title()
</script>
</html>
?
//做這種時間事件的方法很多,本次就分享這一個,希望對你會有幫助.