繁体   English   中英

Javascript多项选择问卷。 我如何更改《准则》,以便可以打多个答案? (与第8个)

[英]Javascript multiple choice questionnaire. How do I change the Code so its possible to tick more than one answer? (with the 8th one)

这是我的测验代码。 我试图以某种方式更改它,但它仍然不允许我选择多个选项。 我需要额外的代码还是必须更改整个代码? 另外,如果有人看到任何错误,请这样说。 先感谢您 :)

<html>
    <head>
        <title>Knowledge Test</title>
        <link rel="stylesheet" href="style folder/styles.css" type="text/css" />
        <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0" />
        <script type="text/javascript">
            var numQuest=8
            var ie=document.all
            function showAnswer(el,ans){
            ie? ie[el].innerHTML='The answer is: '+ ans : document.getElementById(el).innerHTML='The answer is: '+ ans
            }

            function addup()  {
            var q, right, statement, total=0
            questions=new Array();
            for (i = 0; i < numQuest; i++)
            questions[i]=0
            if (document.forms.quiz.q1['right1']){
            for (i = 0; i < numQuest; i++){
            q="q"+(i+1)
            right="right"+(i+1)
            if (document.forms.quiz[q][right].checked)
            questions[i]=1
            }
            }
            else if (document.getElementById){
            for (i = 0; i < numQuest; i++){
            right="right"+(i+1)
            if (document.getElementById(right).checked)
            questions[i]=1
            }
            }
            else
            return;
            for (i = 0; i < numQuest; i++)
            total += questions[i]
            /*///////////Set score /////////////*/
            statement='You scored '+ total +' out of '+ numQuest +' correct, '+ Math.round(total/numQuest*100) +'%'
            ie? ie.results.innerHTML=statement : document.getElementById('results').innerHTML=statement
            }
            function clearR(){
            ie? ie.results.innerHTML='' : document.getElementById('results').innerHTML=''
            for (i = 0; i < numQuest; i++)
            ie? ie["ans"+(i+1)].innerHTML='' : document.getElementById("ans"+(i+1)).innerHTML=''
            }
        </script>
    </head>
    <body>
        <div id="container">

            <header>
                <div class="width">
                    <h1>Quiz</h1>

                    <nav>

                        <ul>
                            <li><a href="index.html">Home</a></li>
                            <li><a href="accessibility.html">Accessibility</a></li>
                            <li><a href="usability.html">Usability</a></li>
                            <li><a href="additional information.html">Additional Information</a></li>
                            <li><a href="how i built this website.html">How I built this Website</a></li>
                            <li><a href="Quiz.html">Quiz</a></li>
                        </ul>   

                    </nav>

                </div>
            </header>
            <div id="body" class="width">
                <center><h1>Test your Knowledge</h1></center>

                <hr>
                <form name="quiz">

                    Question 1:<br>
                    Which HTML attribute is used to define an inline style sheet?<br>
                    <input id="w1a" type="radio" unchecked name="q1"><label for="w1a">class</label><br>
                    <input id="right1" type="radio" unchecked name="q1"><label for="right1">style</label><br>
                    <input id="w1b" type="radio" unchecked name="q1"><label for="w1b">in-style</label><br>
                    <input id="w1c" type="radio" unchecked name="q1"><label for="w1c">font</label><br>
                    <input class="chkans" type="button" value="Check Answer" onclick="showAnswer('ans1','style')">&nbsp;<span id="ans1" class="chkans"></span>
                    <br>&nbsp;<br>
                    Question 2:<br>
                    What is the correct CSS syntax for making all the <"p"> elements bold?<br>
                    <input id="w2a" type="radio" unchecked name="q2"><label for="w2a">p style="text-size:bold"</label><br>
                    <input id="w2b" type="radio" unchecked name="q2"><label for="w2b">p {text-size:bold}</label><br>
                    <input id="right2" type="radio" unchecked name="q2"><label for="right2">p{font-weight:bold}</label><br>
                    <input id="w2c" type="radio" unchecked name="q2"><label for="w2c">p style="font-size:bold"</label><br>
                    <input class="chkans" type="button" value="Check Answer" onclick="showAnswer('ans2','p{font-weight:bold}')">&nbsp;<span id="ans2" class="chkans"></span>
                    <br>&nbsp;<br>
                    Question 3:<br>
                    What does HTML stand for?<br>
                    <input id="w3a" type="radio" unchecked name="q3"><label for="w3a">Hyperlinks and Text Markup Language</label><br>
                    <input id="w3b" type="radio" unchecked name="q3"><label for="w3b">Home Tool Markup Language</label><br>
                    <input id="right3" type="radio" unchecked name="q3"><label for="right3">Hyper Text Markup Laguage</label><br>
                    <input id="w3c" type="radio" unchecked name="q3"><label for="w3c">High Technic Markup Language</label><br>
                    <input class="chkans" type="button" value="Check Answer" onclick="showAnswer('ans3','Hyper Text Markup Laguage')">&nbsp;<span id="ans3" class="chkans"></span>
                    <br>&nbsp;<br>
                    Question 4:<br>
                    What does CSS stand for?<br>
                    <input id="right4" type="radio" unchecked name="q4"><label for="right4">Cascading Style Sheets</label><br>
                    <input id="w4a" type="radio" unchecked name="q4"><label for="w4a">Creative Style Sheets</label><br>
                    <input id="w4b" type="radio" unchecked name="q4"><label for="w4b">Computer Style Sheets</label><br>
                    <input id="w4c" type="radio" unchecked name="q4"><label for="w4c">Colorful Style Sheets</label><br>
                    <input class="chkans" type="button" value="Check Answer" onclick="showAnswer('ans4','Cascading Style Sheets')">&nbsp;<span id="ans4" class="chkans"></span>
                    <br>&nbsp;<br>
                    Question 5:<br>
                    Choose the right text color for a Website with a white background.<br>
                    <input id="right5" type="radio" unchecked name="q5"><label for="right5">black</label><br>
                    <input id="w5a" type="radio" unchecked name="q5"><label for="w5a">orange</label><br>
                    <input id="w5b" type="radio" unchecked name="q5"><label for="w5b">red</label><br>
                    <input id="w5c" type="radio" unchecked name="q5"><label for="w5c">yellow</label><br>
                    <input class="chkans" type="button" value="Check Answer" onclick="showAnswer('ans5','black')">&nbsp;<span id="ans5" class="chkans"></span>
                    <br>&nbsp;<br>
                    Question 6:<br>
                    Where in an HTML document is the correct place to refer to an external style sheet?<br>
                    <input id="w6a" type="radio" unchecked name="q6"><label for="w6a">In the <"head"> section</label><br>
                    <input id="w6b" type="radio" unchecked name="q6"><label for="w6b">At the end of the document</label><br>
                    <input id="right6" type="radio" unchecked name="q6"><label for="right6">At the top of the document</label><br>
                    <input id="w6c" type="radio" unchecked name="q6"><label for="w6c">In the <"body"> section</label><br>
                    <input class="chkans" type="button" value="Check Answer" onclick="showAnswer('ans6','black')">&nbsp;<span id="ans6" class="chkans"></span>
                    <br>&nbsp;<br>
                    Question 7:<br>
                    Which property is used to change the background color?<br>
                    <input id="w7a" type="radio" unchecked name="q7"><label for="w7a">color</label><br>
                    <input id="right7" type="radio" unchecked name="q7"><label for="right7">background-color</label><br>
                    <input id="w7b" type="radio" unchecked name="q7"><label for="w7b">bgcolor</label><br>
                    <input id="w7c" type="radio" unchecked name="q7"><label for="w7c">bgc</label><br>
                    <input class="chkans" type="button" value="Check Answer" onclick="showAnswer('ans7','black')">&nbsp;<span id="ans7" class="chkans"></span>
                    <br>&nbsp;<br>
                    Question 8:<br>
                    On a web page, how and where should be the logo/brand name?(choose 2)<br>
                    <input id="right8" type="radio" unchecked name="q8"><label for="right8">easy</label><br>
                    <input id="right8" type="radio" unchecked name="q8"><label for="right8">upper-left corner of the screen</label><br>
                    <input id="w8a" type="radio" unchecked name="q8"><label for="w8a">in the middle of the screen</label><br>
                    <input id="w8b" type="radio" unchecked name="q8"><label for="w8b">hard</label><br>
                    <input class="chkans" type="button" value="Check Answer" onclick="showAnswer('ans8','easy','upper-left corner of the screen')">&nbsp;<span id="ans8" class="chkans"></span>
                    <br>&nbsp;<br>
                    <!--End of Questions-->
                    <hr><br>
                    <input type="button" value="See Score" onclick="addup()">&nbsp;&nbsp;<span id="results"></span><br>&nbsp;<br>
                    <input type="button" value="Start Again" onclick="reset();clearR()">
                </form>
            </div>
        </div>
    </body>
</html>

使用<input type="checkbox">而不是<input type="radio">

输入type =“ radio”表示从项目列表中选择一个项目

输入type =“ checkbox”表示可以切换的状态或选项

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM