2017-07-30 143 views
-1

我已經使用javascript消失了表單,但是現在我希望在窗體顯示爲無時顯示一行文本,而且我不確定JavaScript的正確布爾運算符是什麼是。使用javascript隱藏和顯示元素

<script> 
 
    function Enter() { 
 
     survey.style.display = "none"; 
 
     if (survey==="none"){ 
 
      thank.style.display = "inline"; 
 
     } 
 
     else { 
 
      thank.style.display = "none"; 
 
     } 
 
    } 
 
</script>
<div id="right"> 
 
    <div id="thank" style=" display: none"> 
 
     Thank you, your message has been sent. 
 
    </div> 
 
    <form name="survey" id="survey" action="" method="post"> 
 
     <input type="submit" value="Contact Us!" onclick="Enter()"/> 
 
    </form> 
 
</div>

錯誤消息:

"message": "SyntaxError: expected expression, got '<'", "filename": " https://stacksnippets.net/js ", "lineno": 13, "colno": 28

+0

可能是你應該嘗試,如果(survey.style.display =='none'){ thank.style.display ='inline'; } – Gunnrryy

+0

嘗試使用雙等於? '=='而不是'==='? –

+0

@PraveenKumar問題在於我的JDK表示它期望'===' – briggleshiggle

回答

0

如果我理解正確的U,

你想有一個線tekst至極的是默認: 「顯示:無」因此:

<p id="MyTekst" style="display: none">My line of tekst</p> 

再加上你的腳本:

<script> 
function Enter() { 
    survey.style.display = "none"; 

    if (survey==="none"){ 
     thank.style.display = "inline"; 
     document.getElementById("MyTekst").style.display = "block"; 
    } 
    else { 
     thank.style.display = "none"; 
    } 
} 
</script> 

讓我們知道,如果它幫助

+1

一旦表單消失,仍然無法顯示文本行。 – briggleshiggle

0

明白了這個工作:

    <script> 

        function Enter() { 
         survey.style.display = "none"; 

         if (survey.style.display==="none"){ 
          thank.style.display = "inline"; 
         } 
        } 
       </script>