2017-07-30 189 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>