簡體   English   中英

在頁面加載時隱藏DIV

[英]Hide DIV on page load

我正在嘗試在頁面加載時隱藏DIV元素,並且單擊“立即購買”按鈕之后,然后加載DIV元素。 現在,它顯示頁面何時加載以及單擊時隱藏,即使我在功能中切換“ block”和“ none”,它仍然不起作用? 誰能幫我隱藏負載嗎?

謝謝

顯示和隱藏腳本:

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

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>

致電者:

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

我會使用CSS來隱藏它:

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

這意味着默認情況下,DIV將被隱藏(根據樣式規則),並且函數將在調用時顯示它。

您代碼的其余部分應該都很好(請記住在單擊時阻止單擊“立即購買”按鈕,以免再次按下它,因此您的DIV將再次隱藏)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM