首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

网上复制过来的一段代码,就是搞不懂那儿报错.该怎么解决

2012-02-17 
网上复制过来的一段代码,就是搞不懂那儿报错.htmlheadscriptlanguage javascript xxnewDate()v

网上复制过来的一段代码,就是搞不懂那儿报错.
<html>
<head>
<script       language= "javascript ">      
    xx=new   Date();

    var       s       =   (xx.getHours()*3600+xx.getMinutes()*60+xx.getSeconds());      

    var       tim_d       =       parseInt(s/86400);      
    var       tim_h       =       parseInt((s%86400)/3600);      
    var       tim_m       =       parseInt(((s%86400)%3600)/60);      
    var       tim_s       =       ((s%86400)%3600)%60;      
    function   setime()      
    {      
if(tim_s> =60)
{      
tim_s   =   0;//60      
if(tim_m> =60)
{      
tim_m=0;//60      
//小时数      
if(tim_h> =24)
{
window.clearTimeout(xx);  
}
tim_h+=1;      
}      
tim_m       +=       1;      
}
tim_s+=1;      

if(tim_s <10)
{
show_s       =       "0 "       +       tim_s;      
}
else
{      
show_s       =       tim_s;      
}      

if(tim_m       <       10)
{      
show_m       =       "0 "       +       tim_m;      
}
else
{      
show_m       =       tim_m;      
}      
if(tim_h       <       10)
{      
show_h       =       "0 "       +       tim_h;      
}
else
{      
show_h       =       tim_h;      
}      
show_d       =       tim_d;

document.write(show_h+ "时 "+show_m+ "分 "+show_s+ "秒 ");      
xx=setTimeout( "setime() ",1000);      
    }      
    </script>  
    <script       language=javascript>      
    var   key=1;  
    if(key==1){
    setime();  
    }    
    </script>
       

<body>
 
</body>

</html>

主要还是想让时钟走动!

[解决办法]
<html>
<head>
<script language= "javascript " >
xx=new Date();



var s = (xx.getHours()*3600+xx.getMinutes()*60+xx.getSeconds());

var tim_d = parseInt(s/86400);
var tim_h = parseInt((s%86400)/3600);
var tim_m = parseInt(((s%86400)%3600)/60);
var tim_s = ((s%86400)%3600)%60;
function setime()
{
if(tim_s> =60)
{
tim_s = 0;//60
if(tim_m> =60)
{
tim_m=0;//60
//小时数
if(tim_h> =24)
{
window.clearTimeout(xx);
}
tim_h+=1;
}
tim_m += 1;
}
tim_s+=1;
if(tim_s <10)
{
show_s = "0 " + tim_s;
}
else
{
show_s = tim_s;
}

if(tim_m < 10)
{
show_m = "0 " + tim_m;
}
else
{
show_m = tim_m;
}
if(tim_h < 10)
{
show_h = "0 " + tim_h;
}
else
{
show_h = tim_h;
}
show_d = tim_d;
document.getElementById( "div1 ").innerHTML=(show_h+ "时 "+show_m+ "分 "+show_s+ "秒 ");
xx=setTimeout( "setime() ",1000);
}
</script>
<script language=javascript defer>
var key=1;
if(key==1){
setime();
}
</script>


<body>
<div id= "div1 ">
</div>
</body>

</html>
[解决办法]
没这么麻烦的,简单一点
<body onload=showTime()>
<span id=sp> </span>
</body>
<script>
function showTime()
{
var o = (new Date()).toLocaleString();
var t = o.split( " ")[1].split( ": ")
var time = t[0]+ "时 "+t[1]+ "分 "+t[2]+ "秒 ";
document.getElementById( 'sp ').innerText = time;
}
setInterval( "showTime(); ",1000);
</script>
[解决办法]
<HTML>
<HEAD>
<TITLE> Test </TITLE>
<SCRIPT LANGUAGE= "JavaScript ">

  function gettime()

  { var t = new Date();

  var hours = t.getHours();

  var minutes = t.getMinutes();

  var seconds = t.getSeconds();

  var show_str = " ";

  show_str +=(hours > 12) ? "下午 ": "上午 ";

  show_str += ((hours > 12) ? hours-12 : hours);

  show_str += ((minutes <10) ? ":0 " : ": ") + minutes;

  show_str += ((seconds <10) ? ":0 " : ": ") + seconds;

  document.show_time.name1.value = show_str;
//document.write(show_str);
  t = setTimeout( "gettime() ",1000);

  }
</SCRIPT>
</HEAD>
<BODY onLoad= "gettime() ">
<BODY>
<FORM NAME= "show_time " onSubmit= "0 ">
<INPUT TYPE= "text " NAME= "name1 " SIZE=16 VALUE= " ">
</FORM>
</BODY>
</HTML>

热点排行