您的位置:首页 > Web前端 > JavaScript

javascript实现时钟的多种方法

2007-05-06 19:39 1066 查看
<!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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: