[英]toggle reveal div with javascript. Start hidden, click to reveal
我想使用單擊按鈕隱藏/顯示div來切換div是否可見。
我有執行此操作的代碼,但是默認情況下,div在頁面加載時可見。 我希望div開始隱藏,並且僅在查看者單擊時才顯示。
這是我當前正在使用的代碼。 有沒有辦法改變這一點,使股利開始隱藏?
<script>
function myFunction() {
var x = document.getElementById('myDIV');
if (x.style.display === 'none') {
x.style.display = 'block';
} else {
x.style.display = 'none';
}
}
</script>
<button onclick="myFunction()">Enquire Now ></button>
<div id="myDIV">
<form action="/post.php" method="post">
<p>Enter your contact details</p>
<p>
Name: <input type="text" name="name"><br>
Tel: <input type="tel" name="tel"><br>
Email: <input type="email" name="email" value="Email Address"></p>
<p><input type="submit"></p>
</form>
</div>
更改
<div id="myDIV">
至
<div id="myDIV" style="display: none;">
您可以使用style
屬性:
<div id="myDIV" style="display: none">
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.