javascript,实现一个时钟,页面显示当前时间包括年月日时 分 秒 并设定一个时间点,当该
1个回答
展开全部
<html>
<head>
<title>Time</title>
</head>
<body>
<div id="time"></div>
<div id="alert"></div>
</body>
<script type="text/javascript" charset="utf-8" async defer>
var time = document.getElementById("time");
showTime();
function showTime() {
// To get the date time
var date = new Date();
var year = date.getYear() + 1900;
var month = date.getMonth() + 1;
var day = date.getDate();
var hour = date.getHours();
var min = date.getMinutes();
var sec = date.getSeconds();
var date_time = year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec;
time.innerHTML = date_time;
// when the time is equal your condition, show the special words.
if(date_time == "2014-6-25 11:45:20") {
document.getElementById("alert").innerHTML = "It's time to display your words here.";
}
}
// set the interval time
setInterval(showTime, 1000);
</script>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询