javascript实现时钟的多种方法

来源:互联网 发布:手机探鱼器软件 编辑:程序博客网 时间:2024/05/16 10:52

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title> Example1 </title>
<style>
body{font-size:34px;color:green;font-weight:bold}
</style>
<script></script>

<script language="JavaScript" type="text/javascript">
<!--
/*document.write("Hello Word !" + "<br>");
//这里是单行注释,这里将不被显示。
document.write(new Date()+"<br>");

这里是多行注释。
在这个区域里的内容都不会被显示。
document.write(new Date().toGMTString()+"<br>");
var date = new Date();
document.write(date.getTime()+"<br>");*/
//-->
</script>


<script language="JavaScript" type="text/javascript" src="Exp.js">
</script>

 

 

 

<script language="JavaScript" type="text/javascript">
<!--
function showTime(){
 var currentTime = new Date(); 
 var strDate = currentTime.getYear() + '年';
 strDate += currentTime.getMonth() + '月';
 strDate += currentTime.getDate() + '日';
 strDate += currentTime.getHours() + ':';
 strDate += currentTime.getMinutes() + ':';
 var second = currentTime.getSeconds();
 if(second<10){
  strDate += '0' + currentTime.getSeconds();
  }else{
  strDate += currentTime.getSeconds();
  }
 alert(strDate);
}
//-->
</script>
<noscript>您的浏览器不支持脚本语言的运行</noscript>
</head>


<body>
<hr>
<b><font size="45px" color="red">这里是body标签里的文本</font></b>
<br><br>
<hr>
<center>
<form method=post action="#">
<input type="button" name="button" value="显示时间" 
 onclick="var currentTime = new Date(); 
    var strDate = currentTime.getYear() + '年';
    strDate += currentTime.getMonth() + '月';
    strDate += currentTime.getDate() + '日';
    strDate += currentTime.getHours() + ':';
    strDate += currentTime.getMinutes() + ':';
    var second = currentTime.getSeconds();
    if(second<10){strDate += '0' + currentTime.getSeconds();
    }else{strDate += currentTime.getSeconds();}
    alert(strDate);"/>
<input type="button" name="button" value="显示时间"  onclick="javascript:showTime()"/>
</form>
<a href="javascript:showTime();alert('欢迎学习JavaScript')">显示时间</a>
</center>
</body>
</html> 

原创粉丝点击