我正在制作一个简单的记忆游戏。我使用了一些 setTimeout。直到某一点,它进展顺利。之后我想添加一个秒表。和邦。我收到了这个错误。
Uncaught TypeError: Property 'setTimeout' of object [object Object] is not a function
在这一行:
function counter(){
ctxCounter.font="100pt Arial";
var fillT= setTimeout( function(){ctxCounter.fillText("3",270,340);} , 100);
var clearT= setTimeout( function(){counterClear();} , 1000);
}
Run Code Online (Sandbox Code Playgroud)
和我的秒表部分的代码。添加此行后,我收到上面写的错误。但是没有秒表,一切都完美无缺。
var timer=0;
var running=false;
function startPause(){
if(running==false){
running=true;
increment();
}
else running=false;
}
function reset(){
timer=0;
running=false;
}
function increment(){
if(running==true){
window.setTimeout=(
function(){
var mins= Math.floor(timer/600);
var secs= Math.floor(timer/10);
var tenths= timer%1000;
var all= mins+":"+secs+":"+tenths;
console.log(all);
increment();
},100);
}
}
Run Code Online (Sandbox Code Playgroud)
我在这里卡了两天。请掌舵我
你的函数有一个错误increment,有一个=之后window.setTimeout
function increment(){
if(running==true){
window.setTimeout(
function(){
var mins= Math.floor(timer/600);
var secs= Math.floor(timer/10);
var tenths= timer%1000;
var all= mins+":"+secs+":"+tenths;
console.log(all);
increment();
},100);
}
}
Run Code Online (Sandbox Code Playgroud)