2010-05-25 45 views
0

工作正常,我有我的選擇啓用形式下面的代碼:我選擇啓用形式並不在Internet Explorer中工作,但在Firefox

<script language="JavaScript"> 
function checkSub() { 
    if (document.signup.email.value.indexOf('@', 0) == -1) { 
     alert("Please fill in your valid Email address.\nYour email should be in the following format: [email protected]"); 
     document.signup.email.focus(); 
     return false 
    } 

    else if (!document.signup.terms.checked) { 
     alert("You must read and agree to the terms"); 
     document.signup.terms.focus(); 
     return false 
    } 

    else { 
     switch (document.signup.extra1.value) { 
     case "Platinum": 
      answer = confirm("By clicking OK you confirm that you have\nalready entered 
        the World Cup Giveaway\nas a Platinum upgrade contributor.\n\nIf you have 
        not yet entered the giveaway\nclick Cancel.\n\nYou can enter using the 
        link at the\nbottom of the page.\n\nIf you have already entered the 
        giveaway\nusing a link other than my invitation link\nyou are not 
        eligible for this offer."); 
      if (!answer) { 
       return false 
      } 
      break; 
     case "Gold": 
      answer = confirm("By clicking OK you confirm that you have\nalready entered 
        the World Cup Giveaway\nas a Gold upgrade contributor.\n\nIf you have not 
        yet entered the giveaway\nclick Cancel.\n\nYou can enter using the link 
        at the\nbottom of the page. \n\nIf you have already entered the 
        giveaway\nusing a link other than my invitation link\nyou are not eligible 
        for this offer."); 
      if (!answer) { 
       return false 
      } 
      break; 


     default: 
      alert("You must sign up as a contributor to the \nWorld Cup Giveaway to take 
       advantage of \nthis offer.\n\nPlease click the link at the bottom of this 
       \npage or at the blog post mentioned below \nto sign up.\n\nIf you have 
       already signed up using \nthis link, please select the upgrade level\nyou 
       chose on signup or select \"Free\" if \nyou signed up as a free 
       contributor.\n\nIf you have already entered the giveaway\nusing a link other 
       than my invitation link\nyou are not eligible for this offer.\n\nNote: This 
       page may not function properly\nif viewed in languages other than English."); 
      return false 
     } 
    } 
} 
</script> 

和HTML

<form action="http://ebizac.com/ar/optin.php" method="post" name="signup" 
onsubmit="return checkSub()"> 
    <input type=hidden name="action" value="addlead"> 
    <input type=hidden name="member" value="2315"> 
    <input type=hidden name="auto" value="7584"> 
    <input type=hidden name="thankyou" value="http://plr.forinternetnewbies.com/Offer1"> 
    <input type=hidden name="resubsetting" value="Y"> 
    <input type=hidden name="resubredirect" value=""> 
    <input type=hidden name="invalid_redirect" value=""> 
    <div style="padding:0 0 0 10px;"> 
     <table border=0 cellspacing=0 cellpadding=2> 
      <tr> 
       <td class="label"> 
        <font size="2" face="arial, verdana"> 
         Name: 
        </font> 
       </td> 
       <td> 
        <input type=text size=20 name="fname"> 
       </td> 
      </tr> 
      <tr> 
       <td class="label" width="150"> 
        <font size="2" face="arial, verdana"> 
         Email address: 
        </font> 
        </span> 
       </td> 
       <td> 
        <input type=text size=20 name="email"> 
       </td> 
      </tr> 
      <tr> 
       <td class="label"> 
        <font size="2" face="arial, verdana"> 
         Upgrade Level: 
        </font> 
       </td> 
       <td> 
        <select size=1 name="extra1"> 
         <option> 
          Haven't Joined Yet 
         </option> 
         <option> 
          Platinum 
         </option> 
         <option> 
          Gold 
         </option> 
         <option> 
          Silver 
         </option> 
         <option> 
          Free 
         </option> 
       </td> 
      </tr> 
      <tr> 
       <td> 
       </td> 
       <td align=center> 
        <input type="checkbox" name="terms" value="agree"> 
        I agree to the terms as described on the 
        <a href="http://short9.com/blog0522-sp" target="_blank">blog post</a> 
       </td> 
      </tr> 
      <tr> 
       <td> 
       </td> 
       <td align=center> 
        <input type="submit" value="Contribute Now"> 
       </td> 
      </tr> 
     </table> 
    </div> 
</form> 

的一切做什麼,我期望在Firefox中,但在Internet Explorer中,switch語句總是轉到默認情況。我在默認情況下使用額外的警報(signup.extra1.value)進行測試,並顯示一個空字符串。

這裏有什麼問題?

回答

0

不知道它的原因(現在不能測試),但你可能想嘗試糾正你<script>元素:

<script type="text/javascript" charset="utf-8"> 
0

我不知道問題到底是什麼,但是當IE提供JavaScript問題時,我使用內置的調試器。 (IE8)我會把

debugger; 

交換機前面,並使用監視窗口中找到的

document.signup.extra1.value 

的價值和它的所有作品。

0

您的選項標籤需要具有「值」屬性。你應該檢查這些。

<option value="1">Gold</option> 
<option value="2">Platinum</option> 
然後在你的腳本

switch(document.form_name.select_name.value) { 
    case '1': alert("Gold"); break; 
    case '2': alert("Platinum"); break; 
} 
+0

只要它具有innerText,就不需要值。 而你的例子將永遠不會工作,因爲從一個選項返回的值總是一個字符串,而不是一個數字(你正在測試) – 2010-05-26 07:51:20

+0

是的,哎呀。你是對的絃樂的事情。但是,我敢肯定,這是一個IE錯誤,因爲我可以重現原始問題,並通過檢查選項標記的值屬性來按照應有的方式工作。 (IE7) – prater 2010-05-26 14:19:49

0

你最有可能有同樣的問題,如Javascript returns Nan in IE, FF ok

首先,與type="text/javascript"更換language="JavaScript"。第一個在一段時間以前就被棄用了。

其次,不要訪問表單元素以這種方式,因爲它是很脆弱的 你可能有更好的運氣使用

  • 給元素的ID和使用的document.getElementById(「foo」的訪問形式元素)
  • 文件。 表格 .signup。 元素 .extra1

這兩個比你現在正在做什麼更好的方法。

相關問題