简体   繁体   English

在页面加载时隐藏DIV

[英]Hide DIV on page load

I'm trying to hide a DIV element when the page loads and after the Purchase now buton is clicked then the DIV element loads. 我正在尝试在页面加载时隐藏DIV元素,并且单击“立即购买”按钮之后,然后加载DIV元素。 Right now it shows when the page loads and when clicked it hides, even when i switch the "block" and "none" around in the function it still does not work? 现在,它显示页面何时加载以及单击时隐藏,即使我在功能中切换“ block”和“ none”,它仍然不起作用? Can anyone please help me to hide it on load? 谁能帮我隐藏负载吗?

Thanks 谢谢

Show & Hide Script: 显示和隐藏脚本:

  function showhide()
     {
     var div = document.getElementById("newpost");
    if (div.style.display !== "none") {
        div.style.display = "none";
    }
    else {
        div.style.display = "block";
    }
     }

DIV element: DIV元素:

<div id="newpost" class="hidden">

    Enter Your First Name:</td> <input type="text"  size="10">
    <br>
    Enter Your Surname: <input type="text"  size="10">
    <br>
    Enter Your Address: <input type="text"  size="10">
    <br>
    Enter Your E-mail: <input type="text"  size="10">
    <br>

    <input type="button" value="Submit Purchase" id="B1" onClick="final()">
</table>
            </div>

Called By: 致电者:

        Basket: <input type="text" id="Total"  disabled="disabled" > <input type="button" value= "Purchase Now" onclick ="showhide()">  <input type="button" value= "Clear Basket" onclick ="showhide()">

I would use a CSS to hide it: 我会使用CSS来隐藏它:

<html>
    <head>
        <title>...</title>
        <style type="text/css">
            #newpost {
                display: none;
            }
        <style>
    </head>
    <body>
        <!-- ...... -->
    </body>
</html>

That means your DIV will be hidden by default (according to style rules) and your function will show it when called. 这意味着默认情况下,DIV将被隐藏(根据样式规则),并且函数将在调用时显示它。

The rest of your code should do fine (remember to block clicking the "Purchase now" button when clicked so it won't be pressed again and, thus, your DIV will hide again). 您代码的其余部分应该都很好(请记住在单击时阻止单击“立即购买”按钮,以免再次按下它,因此您的DIV将再次隐藏)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM