2010-08-29 94 views
0

我爲我們的計算機項目做了一個測驗頁,我最近完成了它。我很高興知道它運行良好。現在的問題是,它只適用於Google Chrome,而不適用於Firefox。當我在Google Chrome中打開它時,一切正常:提示輸入名稱,評分等功能,但在Firefox中無效。需要幫助。在谷歌瀏覽器中使用Javascript編碼,但不在其他瀏覽器上使用FF

<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> 
+2

如果我們要幫忙,我們需要代碼。 :-) – 2010-08-29 14:26:28

+1

今天早上我的精神力量有點弱。你介意給出一些提示,看看代碼是什麼樣子的,它應該做什麼,以及Firefox究竟發生了什麼錯誤? – Pointy 2010-08-29 14:26:30

+1

另外一個好的開始是在你的FireFox上安裝FireBug,然後瀏覽你的JavaScript代碼,看看出了什麼問題。 – 2010-08-29 14:29:12

回答

1

我的Firefox Web Developer Toolbar告訴我,這段代碼運行時:

  • Error: unlabeled break must be inside loop or switch
  • Error: name is not a function

首先是通過與return更換break固定。第二個在修正第一個後消失了。

Firebug也講述了JS控制檯中的相同問題。

+0

OMFG它工作! :DDDDDDDDD 非常感謝! – 2010-08-29 14:46:54

相關問題