<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312">
<title>汉字时间</title>
</head>
<body>
<script defer>

function clock2(index)
{
text = "";
var hanzi = "一二三四五六七八九十";
if(index==0)
{
text = text +"零";
}
else if(index<10)
{
text = text+hanzi.substring(0+(index-1),index);
}
else if(index<20)
{
text ="十"+ text +hanzi.substring(0+(index-11),(index-10));

}
else if(index<30)
{
text ="二十"+ text+hanzi.substring(0+(index-21),(index-20));
}
else if(index<40)
{
text ="三十"+ text +hanzi.substring(0+(index-31),(index-30));

}
else if(index<50)
{
text = "四十"+text+hanzi.substring(0+(index-41),(index-40));
}
else if(index<60)
{
text ="五十"+ text +hanzi.substring(0+(index-51),(index-50));

}
return text;
}
function clock2_1() {
clocker = document.getElementById("timer2");
aaa = new Date();
hours = aaa.getHours();
min = aaa.getMinutes();
seconds= aaa.getSeconds();

clocker.innerHTML=clock2_1(hours);

}
clock2_1();
</script>
<div id="timer"></div>
<div id="timer2"></div>
</body>
</html>

解决方案 »

  1.   

    判断不符合逻辑
    else if(index<60) 
    {
    text ="五十"+ text +hanzi.substring(0+(index-51),(index-50));
    }
    index=1,就变成text ="五十"+ text +hanzi.substring(-50,-49);
      

  2.   

    别听2楼乱忽悠,他连else if的语法都不懂,你innerHTML那行的方法名字写错了而已。
      

  3.   

    你改成clock2就可以了,然后把整十的情况处理下,整十的情况处理的不周到。