2016-09-01 12 views
-5

私はこれを動作させるために私が考えることができるすべてを試しました。私はあなたがJavascriptの関数の中に関数を置くことができることを知っています。私は何をすべきか分からない。誰か助けてくれますか?このコードはなぜ機能しないのですか?

<!DOCTYPE HTML> 
<html> 
<head> 
<link rel="stylesheet" type="text/css" href="stylesheet.css"> 
<title>Slideshow Webpage</title> 
<script> 
var sound = new Audio ("Get low.mp3"); 


function startTimer() { 

setTimeout(countnine, 1000); 
setTimeout(counteight, 2000); 

function ten() { 

document.getElementById("timerText").innerHTML="10"; 
} 

function nine() { 

document.getElementById("timerText").innerHTML="9"; 
} 

function eight() { 

document.getElementById("timerText").innerHTML="8"; 
} 

function seven() { 

document.getElementById("timerText").innerHTML="7"; 
} 

function six() { 

document.getElementById("timerText").innerHTML="6"; 
} 

function five() { 

document.getElementById("timerText").innerHTML="5"; 
} 

function four() { 

document.getElementById("timerText").innerHTML="4"; 
} 

function three() { 

document.getElementById("timerText").innerHTML="3"; 
} 

function two() { 

document.getElementById("timerText").innerHTML="2"; 
} 

function one() { 

document.getElementById("timerText").innerHTML="1"; 
} 
} 
</script> 
</head> 
<body> 
<h1>Testing this website for a webpage</h1> 
<p>This is just a test. I am testing this website out to make a webpage.     </p> 

<div id="timer"> 
<p id="timerText"></p> 
</div> 

<p onclick="startTimer()">Start timer</p> 
</body> 
</html> 

私がこれで間違っていることを教えてください。

+1

と同じように、あなたは何をしようとする、あなたの問題を述べる必要がありますか? –

+0

'countnine'と' counteight'はどこにも定義されていないようです。 –

+0

'counteight'と' countnine'は存在しませんAFAIK – Li357

答えて

-2

このコードを使用してください

<!DOCTYPE HTML> 
 
<html> 
 
<head> 
 
<link rel="stylesheet" type="text/css" href="stylesheet.css"> 
 
<title>Slideshow Webpage</title> 
 
<script> 
 
var sound = new Audio ("Get low.mp3"); 
 

 

 
function startTimer() { 
 
    
 
setTimeout(nine, 1000); 
 
setTimeout(eight, 2000); 
 

 
function ten() { 
 

 
document.getElementById("timerText").innerHTML="10"; 
 
} 
 

 
function nine() { 
 
    
 
document.getElementById("timerText").innerHTML="9"; 
 
} 
 

 
function eight() { 
 

 
document.getElementById("timerText").innerHTML="8"; 
 
} 
 

 
function seven() { 
 

 
document.getElementById("timerText").innerHTML="7"; 
 
} 
 

 
function six() { 
 

 
document.getElementById("timerText").innerHTML="6"; 
 
} 
 

 
function five() { 
 

 
document.getElementById("timerText").innerHTML="5"; 
 
} 
 

 
function four() { 
 

 
document.getElementById("timerText").innerHTML="4"; 
 
} 
 

 
function three() { 
 

 
document.getElementById("timerText").innerHTML="3"; 
 
} 
 

 
function two() { 
 

 
document.getElementById("timerText").innerHTML="2"; 
 
} 
 

 
function one() { 
 

 
document.getElementById("timerText").innerHTML="1"; 
 
} 
 
} 
 
</script> 
 
</head> 
 
<body> 
 
<h1>Testing this website for a webpage</h1> 
 
<p>This is just a test. I am testing this website out to make a webpage.     </p> 
 

 
<div id="timer"> 
 
<p id="timerText"></p> 
 
</div> 
 

 
<p onclick="startTimer()">Start timer</p> 
 
</body> 
 
</html>

+3

なぜこのコードを使うべきですか?彼のコードに何が間違っていたのですか?それを修正するために何を変更しましたか? – Barmar

3

あなたはドントのsetTimeoutを使用し、第二のための任意のsetTimeoutを呼び出す必要があります。このexemple

function startTimer(){ 
 
var count = 10; 
 
var time = setInterval(function(){ 
 
    
 
    if(count==0){ 
 
    clearInterval(time) 
 
    } 
 
    document.getElementById("timerText").innerHTML=count-- 
 
},1000) 
 

 
}
<!DOCTYPE HTML> 
 
<html> 
 
<head> 
 
<link rel="stylesheet" type="text/css" href="stylesheet.css"> 
 
<title>Slideshow Webpage</title> 
 
<script> 
 
var sound = new Audio ("Get low.mp3"); 
 

 

 
</script> 
 
</head> 
 
<body> 
 
<h1>Testing this website for a webpage</h1> 
 
<p>This is just a test. I am testing this website out to make a webpage.     </p> 
 

 
<div id="timer"> 
 
<p id="timerText"></p> 
 
</div> 
 

 
<p onclick="startTimer()">Start timer</p> 
 
</body> 
 
</html>

関連する問題