把 dd 设置为全局变量,并且加上 timer<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html>
<head>
<title>test</title>
</head><script>
var dd = 10; // 毫秒
var timer = null; // 控制暂停function war_djs(){
if(dd > 0){
dd--;
timer = setTimeout("war_djs()",1000);
}
var H = Math.floor(dd / 3600);
var M = Math.floor((dd % 3600) / 60);
var S = dd % 60;
document.getElementById("wmissiont").innerHTML = (H < 10 ? "0" + H : String(H)) + ":" + 
(M < 10 ? "0" + M : String(M)) + ":" + (S < 10 ? "0" + S : String(S));
}function myClear(){
dd = 10;
flag = false;
button1.value = "stop";
if(timer != null){
clearTimeout(timer);
timer = null;
}
}var flag = false;// 控制按钮文字 —— stop 或 go on
function mystop(obj){
if(flag){
obj.value = "stop";
timer = setTimeout("war_djs()",1000);
}else{
obj.value = "go on";
clearTimeout(timer);
}
flag = !flag;
}
</script><body>
<div id="wmissiont"></div> <input  type="button" value="start" onclick="myClear();war_djs()"/> 
<input id="button1"  type="button" value="stop" onclick="mystop(this)"/>
<input  type="button" value="restart" onclick="myClear();war_djs();"/> </body></html>

解决方案 »

  1.   

    在这里dd不能这样去申明变量一定要用参数传进去war_djs()才可以
    怎么改改
      

  2.   

    在这里我都是在.js文件里面调用的
    不必考虑按钮上面的字我想要的stop是能不能直接把时间清零而不是停在那里
      

  3.   

    如果一定要传参数,那就这样,但是一定要定义 timer ,不然无法清空<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html>
    <head>
    <title>test</title>
    </head><script>
    var timer = null;// 修改的地方
    function war_djs(dd,bid,m){ 
    dd--;
    if(dd <0){ 
    return;  
    }else{
    clearTimeout(timer);// 修改的地方
    timer = setTimeout('war_djs('+dd+','+bid+','+m+')',1000); // 修改的地方

    var H = Math.floor(dd / 3600); 
    var M = Math.floor((dd % 3600) / 60); 
    var S = dd % 60; 
    document.getElementById("wmissiont").innerHTML = (H < 10 ? "0" + H : String(H)) + ":" + 
    (M < 10 ? "0" + M : String(M)) + ":" + (S < 10 ? "0" + S : String(S)) 
    }
    // 修改的地方
    function mystop(){
    war_djs(1,2,0);
    }
    </script><body>
    <div id="wmissiont"></div> <input  type="button" value="start" onclick="war_djs(10,2,0)">
    <input  type="button" value="stop" onclick="mystop()"> 
    <input  type="button" value="restart" onclick="war_djs(10,2,0)"></body></html>