当前位置: 代码迷 >> JavaScript >> js记时显示
  详细解决方案

js记时显示

热度:159   发布时间:2012-09-17 12:06:51.0
js倒计时显示
脚本说明:
把如下代码加入<body>区域中
<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
// Take user here after session timed out
timedouturl = "http://www.k688.com";

function Minutes(data) {
for (var i = 0; i < data.length; i++)
if (data.substring(i, i + 1) == ":")
break;
return (data.substring(0, i));
}
function Seconds(data) {
for (var i = 0; i < data.length; i++)
if (data.substring(i, i + 1) == ":")
break;
return (data.substring(i + 1, data.length));
}
function Display(min, sec) {
var disp;
if (min <= 9) disp = " 0";
else disp = " ";
disp += min + ":";
if (sec <= 9) disp += "0" + sec;
else disp += sec; 
return (disp);
}
function Down() { 
sec--;      
if (sec == -1) { sec = 59; min--; }
document.timerform.clock.value = Display(min, sec);
window.status = "Session will time out in: " + Display(min, sec);
if (min == 0 && sec == 0) {
alert("Your session has timed out.");
window.location.href = timedouturl;
}
else down = setTimeout("Down()", 1000);
}
function timeIt() {
min = 1 * Minutes(document.timerform.clock.value);
sec = 0 + Seconds(document.timerform.clock.value);
Down();
}
//  End -->
</script>
<center>
<form name="timerform">
<input type="text" name="clock" size="7" value="2:00">
</form>
</center>


第二步:把<body>区域中的内容改为
<body bgcolor="#fef4d9" OnLoad="timeIt()">

<a href="http://www.alixixi.com/Dev/HTML/jsrun/">欢迎访问阿里西西网页特效集</a>


 

  相关解决方案