2015-05-30 143 views
3

我開發了一個用於隱藏和顯示我的文本框的JavaScript函數。此功能在Mozilla中正常工作,但在Chrome瀏覽器中不起作用。我不知道爲什麼。我的功能:某些JavaScript功能不適用於Chrome瀏覽器,爲什麼?

function selectType() 
{ if(document.getElementById("promotype").value=="Amount") 
    { document.getElementById("typediv").style.display = "none"; 
     document.getElementById("type").value = 'amount'; 
    } 
    if(document.getElementById("promotype").value=="Percentage") 
    { document.getElementById("typediv").style.display = "none"; 
     document.getElementById("type").value = 'percentage'; 
    } 

    if(document.getElementById("promotype").value=="Freesignup") 
    { document.getElementById("amount").style.display = "block"; 
     document.getElementById("typediv").style.display = "block"; 
    } 
    else if(document.getElementById("promotype").value=="Gift cards") 
    { document.getElementById("amount").style.display = "block"; 
     document.getElementById("selectmemberdiv").style.display = "block"; 
     document.getElementById("typediv").style.display = "block"; 
    } 
    else 
    { if(document.getElementById("promotype").value=="Freeride") 
     { document.getElementById("amount").style.display = "none"; 
      document.getElementById("type").value = 'none'; 
      document.getElementById("typediv").style.display = "none"; 
     } 
     else 
      document.getElementById("amount").style.display = "block";  
     document.getElementById("selectmemberdiv").style.display = "none"; 
    } 
} 

首先,當我的頁面加載是在那個時候,我會躲的時候我就降下來點擊在基於的類別,時間顯示我的量文本框後,我的「量」文本框。

但他們爲什麼不在Chrome瀏覽器中工作?

+0

是的,但該功能沒有任何錯誤。 – piyush

+0

意味着它在鉻中工作? – Saty

+0

不適用於鉻? – piyush

回答

1

添加bracket去年else條件

<script> 
    function selectType() 
    { 
     if (document.getElementById("promotype").value == "Amount") 
     { 
      document.getElementById("typediv").style.display = "none"; 
      document.getElementById("type").value = 'amount'; 
     } 
     if (document.getElementById("promotype").value == "Percentage") 
     { 
      document.getElementById("typediv").style.display = "none"; 
      document.getElementById("type").value = 'percentage'; 
     } 

     if (document.getElementById("promotype").value == "Freesignup") 
     { 
      document.getElementById("amount").style.display = "block"; 
      document.getElementById("typediv").style.display = "block"; 
     } 
     else if (document.getElementById("promotype").value == "Gift cards") 
     { 
      document.getElementById("amount").style.display = "block"; 
      document.getElementById("selectmemberdiv").style.display = "block"; 
      document.getElementById("typediv").style.display = "block"; 
     } 
     else 
     { 
      if (document.getElementById("promotype").value == "Freeride") 
      { 
       document.getElementById("amount").style.display = "none"; 
       document.getElementById("type").value = 'none'; 
       document.getElementById("typediv").style.display = "none"; 
      } 
      else 
      {// this bracket 
       document.getElementById("amount").style.display = "block"; 
       document.getElementById("selectmemberdiv").style.display = "none"; 
      }// end else condition 
     } 
    } 

</script> 
相關問題