web 实训知识点_0312

web 实训知识点_0312

Data练习
学习Data()的内置函数
1.练习一
根据用户输入的时间输出问候语。

<script language="JavaScript" type="text/javascript">
            var text=""; day = new Date( ); time = day.getHours( ); 
            if (( time>=0) && (time < 8 ))
            text="早上好!"
            if (( time >= 8 ) && (time < 12))
            text="上午好!"
            if (( time >= 12) && (time < 14))
            text="中午好!"
            if (( time >=14) && (time < 18))
            text="下午好!"
            if ((time >= 18) && (time <= 22))
            text="晚上好!"
            if ((time >= 22) && (time < 24))
            text="晚上好!"
            document.write(text)
            </script>
--------------------- 

注:
1.用户输入一个时间。
2.用变量存储。
3.根据时间判断上、中、下午好或晚上好。
4.给用户输出结果 。
2.练习二
根据用户电脑时间,输出问候语。

<script language="JavaScript" type="text/javascript">
            var text=""; day = new Date( ); time = day.getHours( ); 
            if (( time>=0) && (time < 8 ))
            text="早上好!"
            if (( time >= 8 ) && (time < 12))
            text="上午好!"
            if (( time >= 12) && (time < 14))
            text="中午好!"
            if (( time >=14) && (time < 18))
            text="下午好!"
            if ((time >= 18) && (time <= 22))
            text="晚上好!"
            if ((time >= 22) && (time < 24))
            text="晚上好!"
            document.write(text)
            </script>
--------------------- 

注:
1.根据电脑时间,我们需要获取电脑时间。
2.需要变量来存储。
3.判断分支语句。
4.通过元素来添加时间内容。
Date对象的方法

整数
Seconds和Minutes 0至59
Hours 0至23
Day 0至6(星期几)
Date 1至31(月份中的天数)
Months 0至11(一月至十二月)

学习Date()的内置函数

        var hh= today.getHours();//获得小时、分钟、秒
        var mm=today.getMinutes();
        var ss=today.getSeconds();
        document.getElementById("myclock").innerHTML=hh+":"+mm+":"+ss;
--------------------- 

猜你喜欢

转载自blog.csdn.net/weixin_44762317/article/details/88574098