Javascript编码在Google Chrome中运行,但在FF等其他浏览器上运行

时间:2010-08-29 14:25:03

标签: javascript

我为我们的计算机项目做了一个测验页面,我最近完成了它。我很高兴知道它运行良好。现在的问题是它只适用于谷歌Chrome,但不适用于Firefox。当我在谷歌浏览器中打开它时,一切正常:提示输入名称,得分功能等等。但是在Firefox中没有任何作用。需要帮助。

<html>
    <head>
    <title>Javascript Quiz</title>
    <script type="text/javascript">
    function name()
    {
        var n
        n = prompt("Enter your name")
        document.q.name.value = n
    }
    function score()
    {
        var a
        var s = 0;
        var m

        if (q.answer1.value=="Alex Alfred S. Billones")
        {
            s = s+1
        }
        if (q.answer2.value=="grandfathers")
        {
            s = s+1
        }
        if (q.answer3.value=="b")
        {
            s = s+1
        }
        if (q.answer4.value=="c")
        {
            s = s+1
        }
        if (q.answer5.value=="b")
        {
            s = s+1
        }
        if (q.answer6.value=="Angel" || q.answer6.value=="Rex" || q.answer6.value=="Alejandro")
        {
            s = s+1
        }
        if (q.choicesSet2a.checked==true && q.choicesSet2c.checked==true && q.choicesSet2e.checked==true && q.choicesSet2b.checked==false && q.choicesSet2d.checked==false)
        {
            s = s+1
        }
        if (q.answer8.value=="17")
        {
            s = s+1
        }
        if (q.answer9.value=="a")
        {
            s = s+1
        }
        if (q.answer10.value=="never")
        {
            s = s+1
        }

        // remarks part
        if (s==0)
        {
            m = "You don't know me =("
        }
        if (s>0&&s<=3)
        {
            m = "You probably heard stories about me from someone."
        }
        if (s>=4&&s<=5)
        {
            m = "You've met me."
        }
        if (s>=6&&s<=8)
        {
            m = "You know me well."
        }
        if (s==9)
        {
            m = "You love me! :D"
        }
        if (s==10)
        {
            m = "You're a stalker."
        }
        //end of remarks part

        a = confirm("Are you sure with your answers?")
        if (a==true)
        {
            true
        }
        else
        {
            break
        }
        document.q.final.value = s;
        document.q.remark.value = m;



    }
    </script>
</head>

<body bgcolor="green" text="white" onload="name()">
<center><b>How well do you know me? Take this quiz to find out!</b><br>
            Observe correct capitalization of letters in typing.</center><hr>
<form name="q">
<ol>
    <li>What is my COMPLETE name? (with correct middle initial)<br>
        Answer: <input type="text" name="answer1" value=""/>
    </li>

    <li>
        From who among the following was my name gotten from?<br>
        <select name="answer2">
            <option value=""></option>
            <option value="grandfathers">Grandfathers</option>
            <option value="uncle">Uncle</option>
            <option value="stranger">Stranger</option>
            <option value="famous">Famous person</option>
        </select>
    </li>
    <li>Which of the following is the correct spelling of my family name?<br>
        <input type="radio" name="choicesSet1" onclick="q.answer3.value='a' ">Billiones<br>
        <input type="radio" name="choicesSet1" onclick="q.answer3.value='b'">Billones<br>
        <input type="radio" name="choicesSet1" onclick="q.answer3.value='c' ">Biliones<br>
        <input type="radio" name="choicesSet1" onclick="q.answer3.value='d' ">None of the above.<br>
        <input type="hidden" name="answer3" value=""/>
    </li>

    <li>When is my birthday?<br>
        <input type="radio" name="choicesSet2" onclick="q.answer4.value='a' ">February 14<br>
        <input type="radio" name="choicesSet2" onclick="q.answer4.value='b'">October 17<br>
        <input type="radio" name="choicesSet2" onclick="q.answer4.value='c' ">December 17<br>
        <input type="radio" name="choicesSet2" onclick="q.answer4.value='d' ">March 28<br>
        <input type="hidden" name="answer4" value=""/>
    </li>

    <li>How many siblings do I have?<br>
        <input type="radio" name="choicesSet3" onclick="q.answer5.value='a' ">3<br>
        <input type="radio" name="choicesSet3" onclick="q.answer5.value='b' ">2<br>
        <input type="radio" name="choicesSet3" onclick="q.answer5.value='c' ">1<br>
        <input type="radio" name="choicesSet3" onclick="q.answer5.value='d' ">100<br>
        <input type="hidden" name="answer5" value=""/>
    </li>

    <li>Name one of my siblings. (nickname/first name only) <br>
        Answer: <input type="text" name="answer6" value=""><br>
    </li>

    <li>Which of the following are my hobbies? (only three of them are correct)<br>
        <input type="checkbox" name="choicesSet2a">Playing soccer<br>
        <input type="checkbox" name="choicesSet2b">Studying<br>
        <input type="checkbox" name="choicesSet2c">Surfing the net<br>
        <input type="checkbox" name="choicesSet2d">Drinking<br>
        <input type="checkbox" name="choicesSet2e">Reading<br>
    </li>

    <li>What is my favorite number?<br>
        <select name="answer8">
            <option value=""></option>
            <script type="text/javascript">
                for (c=1;c<=50;c++)
                {
                    document.write("<option value='")
                    document.write(c,"'>",c,"</option>")
                }
            </script>
        </select>
    </li>

    <li>How did I have my front tooth broken?<br>
        <input type="radio" name="choicesSet4" onclick="q.answer9.value='a' ">I fainted.<br>
        <input type="radio" name="choicesSet4" onclick="q.answer9.value='b'">I got punched in the face.<br>
        <input type="radio" name="choicesSet4" onclick="q.answer9.value='c' ">I tripped and fell down.<br>
        <input type="radio" name="choicesSet4" onclick="q.answer9.value='d' ">None of the above.<br>
        <input type="hidden" name="answer9" value=""/>
    </li>

    <li>How many times have I been in a relationship?<br>
        <select name="answer10">
            <option value=""></option>
            <option value="1">1</option>
            <option value="3">3</option>
            <option value="4">4</option>
            <option value="never">Never</option>
        </select>
    </li>

</ol>

    <center>
    <input type="button" value="Well...how did I do?" onclick="score()">
    <input type="reset" value="Reset"/><br><br>
    Thank you for taking the quiz, <input type="text" name="name" size="5">.You scored <input type="text" name="final" id="final" size="1"> out of 10.<br>
    <input type="text" name="remark" size="50">

    </center>
</form>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

我的Firefox Web Developer Toolbar在运行此代码时告诉我以下内容:

  
      
  • 错误:未标记的中断必须在内部循环或切换
  •   
  • 错误:名称不是函数
  •   

首先将break替换为return来解决问题。在修复第一个后,第二个消失了。

Firebug也讲述了JS控制台中的相同问题。