***时间日期***时间和日期分别用按钮来实现相互转换
把下列代码加到网页的<body></body>标签之间 从google下载我的照片管理软件要完成此效果需要三个步骤
第一步:把如下代码加入到<head>区域中
<script language="javascript">
<!-- helpers for jsi page...
// navigation - start
function goback(){
alert("good bye!");
history.go(-1);
}
function getname(str) {
alert("hi, "+ str+"!");
}
function getthedate() {
stopclock();
todays = new date();
thedate = "" + (todays.getmonth()+ 1) +" / "+ todays.getdate() + " / "
+
todays.getyear()
document.clock.face.value = thedate;
}
function showit () {
var now = new date();
var hours = now.gethours();
var minutes = now.getminutes();
var seconds = now.getseconds();
stopclock();
totaltime = (minutes > gettotal)?
(minutes-gettotal):totaltime;
document.clock.face.value = totaltime + " in minutes ";
}
// navigation - stop
// netscapes clock - start
// this code was taken from netscapes javascript documentation at
// www.netscape.com on jan.25.96
var timerid = null;
var totaltime = 0;
var gettotal = 0;
var timerrunning = false;
function stopclock (){
if(timerrunning)
cleartimeout(timerid);
timerrunning = false;
}
function startclock () {
// make sure the clock is stopped
var now = new date();
stopclock();
gettotal=now.getminutes();
getthedate()
showtime();
}
function showtime () {
var now = new date();
var hours = now.gethours();
var minutes = now.getminutes();
var seconds = now.getseconds()
var timevalue = "" + ((hours >12) ? hours -12 :hours)
timevalue += ((minutes < 10) ? ":0" : ":") + minutes
timevalue += ((seconds < 10) ? ":0" : ":") + seconds
timevalue += (hours >= 12) ? " p.m." : " a.m."
document.clock.face.value = timevalue;
timerid = settimeout("showtime()",1000);
timerrunning = true;
}
function showtimer () {
var now = new date();
var hours = now.gethours();
var minutes = now.getminutes();
var seconds = now.getseconds()
var timevalue = "" + ((hours >12) ? hours -12 :hours)
timevalue += ((minutes < 10) ? ":0" : ":") + minutes
timevalue += ((seconds < 10) ? ":0" : ":") + seconds
timevalue += (hours >= 12) ? " p.m." : " a.m."
document.clock.tspent.value = timevalue;
timerid = settimeout("showtime()",1000);
timerrunning = true;
}
// netscapes clock - stop
// end helpers -->
</script>
第二步:把如下代码加入到<body>区域中
<form name="clock" onsubmit="0">
<input type=button value="time" size=12
onclick="showtime()">
<input type=button value="date" size=12
onclick="getthedate()">
<input type="text" name="face" size=12 value="" starttimer()>
</form>
第三步:把“onload="startclock()"”加在<body>标记里
例如:<body onload="startclock()">
-- ------------------------- -----------
htt p: //www.hu oyue. com.cn 活跃网,活跃人群 的论坛,访问活跃网,将给您带来意想不到的收获,还可以免费为您开论坛, 让您免费拥有与朋 友、网友交流的论坛。你是年轻人吗 ?你活跃你就上!
页:
[1]