建议:找本参考书仔细看看switch的用法。
<html>
<head>
<script>
function now1()
{
var now1=new Date();
var hr=now1.getHours();
if (hr<6)
{document.write("凌晨啦,我叼,仲未睡,我顶"+"<br>");}
else if (hr<12)
{document.write("早晨啦,懒睡猪,快起身哆"+"<br>");}
else if (hr<18)
{document.write("下午啦,天气真热哆"+"<br>");}
else
{document.write("哎,终于到晚上啦,睇下电视先"+"<br>");}
}
</script></head>
<body onload=now1()></body>
</html>

解决方案 »

  1.   

    switch (hr)
    {
    case 0:
    case 1:
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
           {document.write("凌晨啦,我叼,仲未睡,我顶"+"<br>");break;}
    case 7:
    case 8:
    case 9:
    case 10:
    case 11:
    case 12:
    {document.write("早晨啦,懒睡猪,快起身哆"+"<br>");break;}
    case 13:
    case 14:
    case 15:
    case 16:
    case 17:
    case 18:
    {document.write("下午啦,天气真热哆"+"<br>");break;}
    case 19:
    case 20:
    case 21:
    case 22:
    case 23:
    {document.write("哎,终于到晚上啦,睇下电视先"+"<br>");break;}
    default:
    document.write("error"+"<br>");
    }
      

  2.   

    switch (hr)
    {
    中间的{}和()去掉!!
    }
      

  3.   

    怎么switch case 这c的select case 不一样的,那么要做到(hr>6 && hr<=12):这样就只能是一个个分开写或者用if else ???ps:楼上的leo963258,你说去掉{}()是怎么去掉啊,你测试成功过???
      

  4.   

    这是switch语句的语法:switch (变量){
    case 值1:
    语句;
    break;
    case 值2:
    语句;
    break; ...................... default:
    语句;
    }注:case后只可是值(字符串或者数字)或者变量名一个简单的例子:<script language="javascript">
    function A(x){
    switch (x){
    case 1:
    t = 1;
    break;
    case 2:
    t = 2;
    break;
    case 3:
    t = 3;
    break;
    default:
    t = 10;
    }
    document.write(t);
    }
    A(3);
    </script>
    结果是3
      

  5.   

    xdspower
    的写法是可以执行的