2017-02-12 16 views
2

3ボタンラジオボタンクイズからスコアの出力を返したいと思います。私はアラートを使用するときに出力を持っているが、クイズはモーダル内に含まれているのでポップアップが欲しくない。私はモーダル内で出力を表示して、きれいに見せるためにInnerHTMLを使用しているが、ボタンは今すぐ出力されません。私は、JQueryを使って結果を表示し、ボタンを隠すことを試してきましたが、これはどちらも役に立たないです。誰も結果を "結果"に印刷する方法を知っていますか?問題はdocument.getElementById("results").innerHtml ("Well done! You scored "+ getScore() +"/"+ tot); innerHTMLプロパティであるJavascript 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> 
 
      

答えて

2

は関数ではありません、あなたは内に値を割り当てる必要があります。

それはdocument.getElementById("results").innerHTML = "Well done! You scored "+ getScore() +"/"+ tot;

+0

ないのでなければなりませんまだ何かを持ち出すことは、ページを印刷しようとするのを止めてしまった。 –

+0

デモ:https://jsfiddle.net/m563ev87/、「innerHTML」ではなく「innerHTML」であることを確認してください。大文字のHTMLに注意してください。 –

+0

すばらしいおかあさん! –

関連する問題