为什么跳过第5个警报框?

时间:2015-04-22 16:22:48

标签: javascript jquery

我尝试提交而不选择所有数字的任何单选按钮。它应该提醒我7次。但是,我只有6个!它似乎跳过了第5个警报框。而且我不知道原因。谁能帮我?谢谢!

library(data.table)
setDT(x)[,.SD[1:3] , Gender]

3 个答案:

答案 0 :(得分:0)

for(i; i < inputs.length; i++){

删除此处i ++

必须是

function checkAnswers(){
    var inputs = document.querySelectorAll('input[type="radio"]');
        var check = 0;
        var score = 0,i=0;
    for(i; i < inputs.length; ){

你只是跳过5除了4 - 而且在4次跳跃之后 - 你有+4输入 - 并且跳跃引发了五个问题

答案 1 :(得分:0)

更改

i += 4;

i += 3;

因为for(i;i<inputs.length;i++)你已经在i++

答案 2 :(得分:0)

尝试使用相同的代码:

<html>
<head>
<style type="text/css">
h1{
    width:100%;
    background-color:maroon;
    color:white;

}

fieldset{
    width:500px;
    margin:auto;
}





</style>
<script>


function checkAnswers(){
    var inputs = document.querySelectorAll('input[type="radio"]');
        var check = 0;
        var score = 0,i=0;
    for(i;i<inputs.length;i++){
      var inputName = inputs[i].getAttribute("name"); 
            var checker = document.getElementsByName(inputName);            
            var counter = false;
            for(j=0;j<checker.length;j++){
                if(checker[j].checked == true){
                    counter = true;
                    i += 3;
                    break;
                }
            }
            if(counter == false){
                alert("Must answer question number" + " " + inputName +"!");
                document.getElementById('HG-' + inputName).style.backgroundColor = "red";
                i += 3;
                check++;
            }
            else{
                document.getElementById('HG-' + inputName).style.backgroundColor = "white";

            }
    }

    if(check == 0){
        for(i=0;i<inputs.length;i++){
        var inputName = inputs[i].getAttribute('name');            
        var msg = document.getElementById('msg-' + inputName);
        var store;

        if(inputs[i].value == "yes" && inputs[i].checked == true){
            msg.innerHTML = 'Correct Answer!';
                        document.getElementById('msg-' + inputName).style.color = "green"; 
                        document.getElementById('HG-' + inputName).style.backgroundColor = "white";  
                        score++;   
        }
                else if(inputs[i].value == "no" && inputs[i].checked == true){
                        msg.innerHTML = 'Wrong Answer!';
                        document.getElementById('msg-' + inputName).style.color = "red";
                        document.getElementById('hg-' + inputName).style.backgroundColor = "yellow";
                        document.getElementById('HG-' + inputName).style.backgroundColor = "white";
                }

    }
    document.getElementById("score").innerHTML="Your score is:" + score;
  return false;
    }
return false;


}

</script>
</head>
<body>
<form name="myForm" onsubmit="return checkAnswers()" id="form">
    <center><h1>QUESTIONS</h1></center>
        <fieldset><br />
        <div id="HG-one">
        <span id="msg-one"></span>
    <span>1.) It is a simple design language intended to simplify the process of maing web pages presentable.</span><br /> </div><br />
    <input name="one" type="radio" value="yes" /><span id="hg-one">A. CSS</span><br />
    <input name="one" type="radio" value="no"  />B. HTML <br />
    <input name="one" type="radio" value="no"  />C. XML <br />
    <input name="one" type="radio" value="no"  />D. Bootstrap <br /><br />
    </fieldset>

        <br /><br />
        <fieldset><br />
        <div id="HG-two">
        <span id="msg-two"></span>
        <span>2.) Where is the Eiffel Tower located?</span><br /></div><br />

    <input name="two" type="radio" value="no"  />A. Miag ao<br />
    <input name="two" type="radio" value="yes"  /><span id="hg-two">B. Paris</span><br />
    <input name="two" type="radio" value="no"  />C. Madrid<br />
    <input name="two" type="radio" value="no"  />D. Korea<br />
   </fieldset>

        <br /><br />
        <fieldset><br />
        <div id="HG-three">
        <span id="msg-three"></span>
        <span>3.) Which country produces Proton cars?</span><br /></div><br />

    <input name="three" type="radio" value="no"  />A. Indonesia <br />
    <input name="three" type="radio" value="yes"  /><span id="hg-three">Malaysia</span><br />
    <input name="three" type="radio" value="no"  />C. Japan<br />
    <input name="three" type="radio" value="no"  />D. South Korea<br />
   </fieldset>


        <br /><br />
        <fieldset><br />
        <div id="HG-four">
        <span id="msg-four"></span>
        <span>4.) What is the name of the tallest structure ever built?</span><br /></div><br />

    <input name="four" type="radio" value="no"  />A. Grollo Tower <br />
    <input name="four" type="radio" value="no"  />B. CN Tower<br />
    <input name="four" type="radio" value="yes"  /><span id="hg-four">C. Burj Khalifa</span><br />
    <input name="four" type="radio" value="no"  />D. Taipei 101<br />
   </fieldset>


        <br /><br />
        <fieldset><br />
        <div id="HG-five">
        <span id="msg-five"></span>
        <span>5.) What type of creature is the children's animated character Pingu?</span><br /></div><br />

    <input name="five" type="radio" value="no"  />A. Porcupine <br />
    <input name="five" type="radio" value="no"  />B. Pony<br />
    <input name="five" type="radio" value="no"  />C. Pelican<br />
    <input name="five" type="radio" value="yes"  /><span id="hg-five">D. Penguin</span> <br />
   </fieldset>

        <br /><br />
        <fieldset><br />
        <div id="HG-six">
        <span id="msg-six"></span>
        <span>6.)  What is the longest river in Pakistan?</span><br /></div><br />

    <input name="six" type="radio" value="no"  />A. Incara <br />
    <input name="six" type="radio" value="no"  />B. Indeema<br />
    <input name="six" type="radio" value="no"  />C. Indira<br />
    <input name="six" type="radio" value="yes"  /><span id="hg-six">D. Indus</span> <br />
   </fieldset>

        <br /><br />
        <fieldset><br />
        <div id="HG-seven">
        <span id="msg-seven"></span>
        <span>6.)  What is the longest river in Pakistan?</span><br /></div><br />

    <input name="seven" type="radio" value="no"  />A. Incara <br />
    <input name="seven" type="radio" value="no"  />B. Indeema<br />
    <input name="seven" type="radio" value="no"  />C. Indira<br />
    <input name="seven" type="radio" value="yes"  /><span id="hg-seven">D. Indus</span> <br />
   </fieldset>

        <center><input type="submit" name='submit' value="Submit"  /><br /><br />
        <span id="score"></span><br />
</form>



</body>
</html>

我已将i += 4;更改为i += 3;