<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<button id="time">点此获取系统时间</button>
<script>
var time = document.getElementById('time')
time.onclick = function () {
var time = new Date()
var hour = time.getHours();
if (hour <= 6) {
console.log('等着猝死吧!')
} else if (hour <= 9) {
console.log('早上好')
} else if (hour <= 12) {
console.log('上午好')
} else if (hour <= 14) {
console.log('中午好')
} else if (hour <= 17) {
console.log('下午好')
} else if (hour <= 19) {
console.log('早上好')
} else if (hour <= 22) {
console.log('早上好')
} else {
console.log('夜里好')
}
}
</script>
</body>
</html>
【JS】关于实现系统时间控制台显示问候语
最新推荐文章于 2024-04-18 14:17:52 发布