방금 코딩을 시작했습니다. 나는 퀴즈를 만들었고 학생들이 정답을 클릭 할 때 소리를 내기를 원합니다. 그리고 그들이 틀린 답을 클릭했을 때 또 다른 소리가 나기를 원합니다. 일부 게시물을 온라인에서 찾았지만 작동하지 않습니다. 누구든지 도와 줄 수 있습니까? 미리 감사드립니다.자바 스크립트에서 버튼을 클릭 할 때 소리 추가
자바 스크립트 :
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>
내가 어떠한'audio' 요소를 볼 수 없습니다 당신의 HTML/JS ... – Rayon
참조하십시오 ['