今天学习定义个根据时间而展现文本
在了解js和c语言差不多后,学起来也变得容易了许多了呢。
代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>配合javascript</title>
<link rel="shortchu icon" href="剪辑/图片/加油.jpg">
</head>
<body>
<button type="button" onclick="myfunction()">点我获得好心情</button>
<P id="demo"></P>
<script>
function myfunction()
{
var x=" ";
var time=new Date().getHours();
if(time<=9&&time>=0)
{
x="Good Moring!";
}
else if(time>=9&&time<=18)
{
x="Good afternoon!";
}
else
{
x="Good Evening!";
}
document.getElementById("demo").innerHTML=x;
}
</script>
</body>
</html>
比较常规的判断语句。