JS显示欢迎页面和当前时间
2011-11-04 16:06
381 查看
//ch4_examp7.html
//运行下面的代码
<script type="text/javascript">
var greeting;
var nowDate = new Date();
var nowHour = nowDate.getHours();
var nowMinute = nowDate.getMinutes();
var nowSecond = nowDate.getSeconds();
if (nowMinute < 10)
{
nowMinute = "0" + nowMinute;
}
if (nowSecond < 10) {
nowSecond = "0" + nowSecond;
}
if (nowHour < 12) {
greeting = "Hi,Good Morning";
}
else if (nowHour < 17) {
greeting = "Hi,Good Afternoon";
}
else {
greeting = "Hi,Good Evening";
}
document.write("<h4>" + greeting + " and welcome to my website!</h4>");
document.write("According to your clock the time is");
document.write(nowHour + ":" + nowMinute + ":" + nowSecond);
</script>
显示结果:
![](http://img1.51cto.com/attachment/201111/160614472.png)
本文出自 “重头再来!” 博客,请务必保留此出处http://myjieli.blog.51cto.com/135162/706104
//运行下面的代码
<script type="text/javascript">
var greeting;
var nowDate = new Date();
var nowHour = nowDate.getHours();
var nowMinute = nowDate.getMinutes();
var nowSecond = nowDate.getSeconds();
if (nowMinute < 10)
{
nowMinute = "0" + nowMinute;
}
if (nowSecond < 10) {
nowSecond = "0" + nowSecond;
}
if (nowHour < 12) {
greeting = "Hi,Good Morning";
}
else if (nowHour < 17) {
greeting = "Hi,Good Afternoon";
}
else {
greeting = "Hi,Good Evening";
}
document.write("<h4>" + greeting + " and welcome to my website!</h4>");
document.write("According to your clock the time is");
document.write(nowHour + ":" + nowMinute + ":" + nowSecond);
</script>
显示结果:
![](http://img1.51cto.com/attachment/201111/160614472.png)
本文出自 “重头再来!” 博客,请务必保留此出处http://myjieli.blog.51cto.com/135162/706104
相关文章推荐
- js获取当前时间显示在页面上
- js在页面显示当前时间、日期
- 用js实现倒计时和在页面显示当前时间
- js在页面显示当前时间
- 用js实现页面显示当前日期和时间的代码
- 用js实现页面显示当前日期和时间的代码
- 实现页面实时显示当前时间 js
- JS实现HTML页面中动态显示当前时间完整示例
- 页面上显示当前的时间的js
- js获取当前时间显示在页面上并每秒刷新
- jsp页面利用js动态显示当前系统时间
- js显示当前的时间直接输出到页面
- 网页页面显示当前时间js
- js获取当前时间显示在页面上
- js获取当前时间显示在页面上并每秒刷新
- 使用js获取系统当前时间并在页面显示
- JS在页面上显示当前日期和时间
- js显示当前系统时间的代码
- JS跳转页面,实时显示剩余跳转时间--经过了测试
- 使用js代码在aspx页面动态显示当前日期和时间