我剛開始編碼。我做了一個測驗,我希望在學生點擊正確答案時播放聲音,並在他們點擊錯誤答案時播放另一個聲音。我在網上發現了一些帖子,但他們沒有工作。誰能幫忙?先謝謝你!在javascript中點擊按鈕時添加聲音
的Javascript:
function checkAnswer(){
myAnswer=$('#inputBox').val();
if(myAnswer.slice(myAnswer.length-1,myAnswer.length)==" "){
myAnswer=myAnswer.slice(0,myAnswer.length-1);}
if(currentAnswer==myAnswer){
score++;
$('#feedback').append('<img src="tick.png">');
$('#inputBox').css("background-color","green");
$('#inputBox').css("color","white");
}
else{
$('#feedback').append('<img src="cross.png">');
$('#inputBox').css("background-color","red");
$('#inputBox').css("color","white");
$('#inputBox').val($('#inputBox').val()+" (ans= "+currentAnswer+")");
}
$('#message').append('Press ENTER again to continue');
$("#inputBox").prop('disabled', true);
$("#gameArea").focus();
gamePosition=2;
if(currentQuestionNumber==numberOfQuestions){gamePosition=3;}
}//checkAnswer
HTML:
<!DOCTYPE HTML>
<head>
<title>Quiz</title>
<meta name=viewport content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link href="main.css" rel="stylesheet" type="text/css"/>
<link href="mainclock.css"rel="stylesheet"type="text/css"/>
<script src="jquery.js"></script>
<script src="controller.js"></script>
</head>
<body>
<div id="gameArea" tabindex="1"></div>
<div id="mainStage">
</div>
</body>
我在HTML/JS中看不到任何'audio'元素... – Rayon
請參閱['