<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/htmlcharset=UTF-8">
<title>RunJS</title>
<script type="text/javascript" src="http://sandbox.runjs.cn/uploads/rs/289/za0sqcyf/jquery-1.6.min.js"></script>
<script type="text/javascript">
var t = 3 //设置一个跳转秒数
$(function(){
setInterval("count()",1000) //定义一个定时器
$("#timeCount").html(t) //显示当前的秒数
})
function count(){
t -- //秒数自减
if(t >= 0){
$("#timeCount").html(t) //刷新当前的秒数,重新显示秒数
}else{
clearInterval()//这个可以不用,因为页面都要跳转了,要了也没多大差别
window.location.href="http://www.baidu.com" // 设置跳转的链接
}
}
</script>
</head>
<body>
<div>
<span id="timeCount" style="color:red">
</span>
<span style="color:greenfont-weight:bold">
秒正在退出。。。
</span>
</div>
</body>
</html>
这个是例子,代码你自己查看源代码吧。。。
<html><body>
<input type="text" id="clock" size="35" />
<script language=javascript>
var int=self.setInterval("clock()",50)// 注意:这里单位是毫秒,即50毫秒
function clock()
{
var t=new Date()
document.getElementById("clock").value=t
}
</script>
</form>
<button onclick="int=window.clearInterval(int)">
Stop interval</button>
</body>
这样写就可以了不过是用JavaScript的:<html>
<head>
<script LANGUAGE="JavaScript">
<!-- Hide
var timerID = null
var timerRunning = false
function MakeArray(size)
{
this.length = size
for(var i = 1i <= sizei++)
{
this[i] = ""
}
return this
}
function stopclock (){
if(timerRunning)
clearTimeout(timerID)
timerRunning = false
}
function showtime () {
var now = new Date()
var year = now.getYear()
var month = now.getMonth() + 1
var date = now.getDate()
var hours = now.getHours()
var minutes = now.getMinutes()
var seconds = now.getSeconds()
var day = now.getDay()
Day = new MakeArray(7)
Day[0]="SUN"
Day[1]="MON"
Day[2]="TUE"
Day[3]="WED"
Day[4]="THU"
Day[5]="FRI"
Day[6]="SAT"
var timeValue = ""
timeValue += (Day[day]) + " "
timeValue += ((month <10) ? " 0" : " ") + month + "-"
timeValue += date + "-" + year + " "
timeValue += ((hours <= 12) ? hours : hours - 12)
timeValue += ((minutes <10) ? ":0" : ":") + minutes
timeValue += ((seconds <10) ? ":0" : ":") + seconds
timeValue += (hours <12) ? " AM" : " PM"
document.jsfrm.face.value = timeValue
timerID = setTimeout("showtime()",1000)
timerRunning = true
}
function startclock () {
stopclock()
showtime()
}
//-->
</script>
</head>
<body onload="startclock()">
<form NAME='jsfrm'>
<INPUT TYPE=text NAME='face' size=35 value=''>
</form>
</body>
</html>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)