JS如何暂停时间。 自己定义了个时间函数;获得当前系统时间,时分秒。再用一个按钮事件来开始、暂停时间;该如何做。详细说明,注释 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 var flag=true;function changeFlag(){ var but1=document.getElementById("but1"); if(flag){ flag=false; but1.value="开始"; }else{ flag=true; but1.value="停止"; }}setInterval(function(){ if(flag){...执行时间刷新 }},1000);<input id="but1" type="button" onlick="changeFlag();" value="停止"/> clearTimeout(t1) t1为setTimeout()返回的值 setTimeout 设置时间就行 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title> new document </title><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><style>.clockwrap td{font-size:32px; font-family:Arial;text-align:center;color:#333}.clockwrap td#clock_sec{font-size:12px; padding:10px 0 0 2px;font-weight:normal}.clockwrap td#maohao{width:26px;overflow:hidden;font-size:24px;}</style></head><body><div id="clockwrap" class="clockwrap"><table><tbody><tr><td>00</td><td id="maohao">:</td><td>00</td><td id="clock_sec">00</td></tr></tbody></table></div><input type="button" value="stop" onclick="fPas();" /><input type="button" value="start" onclick="fGo()" /><script type="text/javascript">var clock = { timer: null, showTime: function(hour1, hour2, min1, min2, sec1, sec2) { document.getElementById('clockwrap').innerHTML = '<table><tr><td>' + hour1 + hour2 + '</td><td id="maohao">:' + '</td><td>' + min1 + min2 + '</td><td id="clock_sec">' + sec1 + sec2 + '</td></tr></table>'; }, start: function() { this.timer = setInterval(function() { var now = new Date(), h = ('0' + now.getHours()).slice(-2), m1 = Math.floor(now.getMinutes() / 10), m2 = now.getMinutes() % 10, s1 = Math.floor(now.getSeconds() / 10), s2 = now.getSeconds() % 10; clock.showTime(h.charAt(0),h.charAt(1), m1, m2, s1, s2); }, 1000); }, stop: function() { window.clearInterval(this.timer); }};clock.start();function fPas() { clock.stop(); }function fGo() { clock.start(); }</script></body></html> 关于jquery的小问题 抢购倒计时问题,谢谢! windows2003中如何获取iframe的innerHTML 关于继承机制 关于FIREFOX KEYCODE HTTPS下 数据岛载入XML失败,不知道为什么? 求助:判断字符长度的正则表达式 单元格跳转问题,请赐教。谢谢!~~~ 用JS判断日期格式YYYY-MM-DD要怎么写? 救命啊!这个不大不小的问题应该怎么办啊!!!! ASP中如何将多行的查询结果转化成JSON字符串,JS这边又如何取值 YUI中用JSON的问题,急急急急急急!!!
function changeFlag(){
var but1=document.getElementById("but1");
if(flag){
flag=false;
but1.value="开始";
}else{
flag=true;
but1.value="停止";
}
}
setInterval(function(){
if(flag){
...执行时间刷新
}
},1000);<input id="but1" type="button" onlick="changeFlag();" value="停止"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
.clockwrap td{font-size:32px; font-family:Arial;text-align:center;color:#333}
.clockwrap td#clock_sec{font-size:12px; padding:10px 0 0 2px;font-weight:normal}
.clockwrap td#maohao{width:26px;overflow:hidden;font-size:24px;}
</style>
</head>
<body>
<div id="clockwrap" class="clockwrap"><table><tbody><tr><td>00</td><td id="maohao">:</td><td>00</td><td id="clock_sec">00</td></tr></tbody></table></div>
<input type="button" value="stop" onclick="fPas();" /><input type="button" value="start" onclick="fGo()" />
<script type="text/javascript">
var clock = {
timer: null,
showTime: function(hour1, hour2, min1, min2, sec1, sec2) {
document.getElementById('clockwrap').innerHTML = '<table><tr><td>' +
hour1 + hour2 +
'</td><td id="maohao">:' +
'</td><td>' +
min1 + min2 +
'</td><td id="clock_sec">' +
sec1 + sec2 +
'</td></tr></table>';
},
start: function() {
this.timer = setInterval(function() {
var now = new Date(),
h = ('0' + now.getHours()).slice(-2),
m1 = Math.floor(now.getMinutes() / 10),
m2 = now.getMinutes() % 10,
s1 = Math.floor(now.getSeconds() / 10),
s2 = now.getSeconds() % 10;
clock.showTime(h.charAt(0),h.charAt(1), m1, m2, s1, s2);
}, 1000);
},
stop: function() {
window.clearInterval(this.timer);
}
};
clock.start();
function fPas() { clock.stop(); }
function fGo() { clock.start(); }
</script>
</body>
</html>