Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
I';我正在尝试使用JavaScript制作一个简单的秒表_Javascript - Fatal编程技术网

I';我正在尝试使用JavaScript制作一个简单的秒表

I';我正在尝试使用JavaScript制作一个简单的秒表,javascript,Javascript,这是一个脚本,我在我的网站上做了一个简单的秒表,我已经做了很多年了,毕竟,秒表不会改变数字,它只是保持在00:00:00.00 这是我的剧本: <script> t = 0; tt = 0; s = 0; ss = 0; m = 0; mm = 0; h = 0; hh = 0; function increment() { t++; if (t > 9) {

这是一个脚本,我在我的网站上做了一个简单的秒表,我已经做了很多年了,毕竟,秒表不会改变数字,它只是保持在00:00:00.00

这是我的剧本:

<script>
    t  = 0;
    tt = 0;
    s  = 0;
    ss = 0;
    m  = 0;
    mm = 0;
    h  = 0;
    hh = 0;

    function increment() {
        t++;

        if (t  > 9) { t  = 0; tt++ };
        if (tt > 9) { tt = 0; s++  };
        if (s  > 9) { s  = 0; ss++ };
        if (ss > 5) { ss = 0; m++  };
        if (m  > 9) { m  = 0; mm++ };
        if (mm > 5) { mm = 0; h++  };
        if (h  > 9) { h  = 0; hh++ };
        if (hh > 9) { hh = 0;      };

        setTimeout(increment, 10);
    }

    increment();

    stopwatch = document.createElement("div");
    // stopwatch.setAttribute("class","stopwach") etc.
    stopwatch.innerHTML = '<h2>' + hh + h + ':' + mm + m + ':' + ss +
         s + '.' + tt + t + '</h2>';

    var maindivElement = document.getElementById("maindiv");
    var anchorElements = maindivElement.getElementsByTagName("a")…
    // maindivElement.insertBefore(stopwatch, etc.
</script>

t=0;
tt=0;
s=0;
ss=0;
m=0;
mm=0;
h=0;
hh=0;
函数增量(){
t++;
如果(t>9){t=0;tt++};
如果(tt>9){tt=0;s++};
如果(s>9){s=0;ss++};
如果(ss>5){ss=0;m++};
如果(m>9){m=0;mm++};
如果(mm>5){mm=0;h++};
如果(h>9){h=0;hh++};
如果(hh>9){hh=0;};
设置超时(增量,10);
}
增量();
秒表=document.createElement(“div”);
//stopwatch.setAttribute(“类”、“stopwach”)等。
stopwatch.innerHTML='+hh+h+':'+mm+m+':'+ss+
s+'.+tt+t+'';
var maindivElement=document.getElementById(“maindiv”);
var anchoreElements=maindivElement.getElementsByTagName(“a”)…
//maindivElement.insertBefore(秒表等。

请帮助!

您的函数增量在循环中,但实际上对UI没有任何作用

我认为应该是这样的:

function increment() {
    t++;
    if (t > 9) {t = 0; tt++};
    if (tt > 9) {tt = 0; s++};
    if (s > 9) {s = 0; ss++};
    if (ss > 5) {ss = 0; m++};
    if (m > 9) {m = 0; mm++};
    if (mm > 5) {mm = 0; h++};
    if (h > 9) {h = 0; hh++};
    if (hh > 9) {hh = 0;};

    $("div").html('<h2>' + hh + h + ':' + mm + m + ':' + ss + s + '.' + tt + t + '</h2>');
}
setInterval(increment,1000);
函数增量(){
t++;
如果(t>9){t=0;tt++};
如果(tt>9){tt=0;s++};
如果(s>9){s=0;ss++};
如果(ss>5){ss=0;m++};
如果(m>9){m=0;mm++};
如果(mm>5){mm=0;h++};
如果(h>9){h=0;hh++};
如果(hh>9){hh=0;};
$(“div”).html(“+hh+h+”:“+mm+m+”:“+ss+s+”。+tt+t+”);
}
设置间隔(增量,1000);

为什么代码会被切断?类似的问题:javascript-jquery:stopwatch-Stack Overflow这不是你使用
setTimeout
的方式。有没有理由做
function(){increment()}
而不仅仅是
increment
?我说的是
increment
,不是
increment()
.FTFY