3 버튼 라디오 퀴즈에서 점수의 결과를 반환하고 싶습니다. 나는 경보를 사용할 때 출력을 가지고 있지만 퀴즈가 모달에 포함되어 있으므로 팝업을 원하지 않습니다. 모달 내에서 출력을 표시하여 깨끗하게 보이게하고 싶습니다. 그러나 클릭 할 때 InnerHTML을 사용하고 있습니다. 이제 버튼이 출력되지 않습니다. 나는 JQuery를 사용하여 결과를 보여주고 버튼을 숨기기 위해 실험을 해왔다. 그러나 이것은 도움이되지 않는다. 아무도 결과를 인쇄 할 수있는 방법을 알고 있습니까? document.getElementById("results").innerHtml ("Well done! You scored "+ getScore() +"/"+ tot);
innerHTML을이 함수가 아닙니다으로자바 스크립트 innerHtml 퀴즈 결과
감사
<script>
var answers = ["A","B","B"],
tot = answers.length;
function getCheckedValue(radioName){
var radios = document.getElementsByName(radioName); // Get radio group by-name
for(var y=0; y<radios.length; y++)
if(radios[y].checked) return radios[y].value; // return the checked value
}
function getScore(){
var score = 0;
for (var i=0; i<tot; i++)
if(getCheckedValue("question"+i)===answers[i]) score += 1; // increment only
return score;
}
function returnScore(){
print("Your score is "+ getScore() +"/"+ tot);
}
</script>
var answers = ["A","B","B"],
tot = answers.length;
function getCheckedValue(radioName){
var radios = document.getElementsByName(radioName); // Get radio group by-name
for(var y=0; y<radios.length; y++)
if(radios[y].checked) return radios[y].value; // return the checked value
}
function getScore(){
var score = 0;
for (var i=0; i<tot; i++)
if(getCheckedValue("question"+i)===answers[i]) score += 1; // increment only
return score;
}
function returnScore(){
document.getElementById("results").innerHtml ("Well done! You scored "+ getScore() +"/"+ tot);
}
</script>
<p> You are only charged interest on the amount that is remaining at the end of the month<br>
<input type="radio" name="question0" value="A"> True </radio>
<input type="radio" name="question0" value="B"> False </radio> <br><hr>
</p>
<p>I have to pay off the balance in full every month <br><p>
<input type="radio" name="question1" value="A"> True </radio>
<input type="radio" name="question1" value="B"> False </radio> <br> <hr>
<p>If I don't make a payment my credit score will be unaffected <br></p>
<input type="radio" name="question2" value="A"> True </radio>
<input type="radio" name="question2" value="B"> False </radio>
<br><br>
<button type="button" class="btn btn-primary btn-xl page-scroll" onclick = "returnScore()">Results</button>
<h4 id="results"> </h4>
아닌가요 무엇이든을 기르는 것은 아직도 페이지를 인쇄하는 것을 시도하는 중지했다. –
데모 : https://jsfiddle.net/m563ev87/, 'innerHTML'이 아니라'innerHTML'이 아닌 대문자가 있는지 확인하십시오. 대문자 HTML –
감사합니다! –