簡體   English   中英

我怎么做<div>單擊按鈕時部分不可見(JS)?</div><div id="text_translate"><p> 如何使用 JS 隱藏&lt;div&gt;部分和</p><pre>&lt;div class="alertB1"&gt; &lt;div class="sticky"&gt; &lt;h1&gt; This site is still being built&lt;/h1&gt; &lt;p&gt; Please remember this site is still being built. Click &lt;a href="form1.html"&gt;here to report a bug &lt;/a&gt; &lt;/div&gt; &lt;/div&gt; &lt;style&gt;.sticky { position: -webkit-sticky; position: sticky; }.alertB1 { width: 100%; height: 125px; background: lightgreen; } &lt;/style&gt;</pre><p> 所以我希望包含一個按鈕:</p><pre> &lt;span id="a33"&gt;&lt;button&gt;&amp;times;&lt;/button&gt;&lt;/span&gt; &lt;/div&gt; &lt;/div&gt;</pre><p> 如何讓&lt;span&gt;隱藏&lt;div&gt;標簽? 謝謝,環形游戲</p></div>

[英]How do i make a <div> section invisible when a button is clicked (JS)?

如何使用 JS 隱藏<div>部分和

<div class="alertB1">
<div class="sticky">
<h1> This site is still being built</h1>
<p> Please remember this site is still being built. Click <a href="form1.html">here to report a bug </a>
</div>
</div>
<style>
.sticky {
position: -webkit-sticky;
position: sticky;
}
.alertB1 {
width: 100%;
height: 125px;
background: lightgreen;
}

</style>

所以我希望包含一個按鈕:

<span id="a33"><button>&times;</button></span>
</div>
</div>

如何讓<span>隱藏<div>標簽? 謝謝,環形游戲

使用onclick屬性;

更多信息: DOM onevent 處理程序

 .sticky { position: -webkit-sticky; position: sticky; }.alertB1 { width: 100%; height: 125px; background: lightgreen; }
 <div class="alertB1"> <div class="sticky"> <h1> This site is still being built</h1> <p> Please remember this site is still being built. Click <a href="form1.html">here to report a bug </a></p> <span onclick="document.getElementsByClassName('alertB1')[0].style.display = 'none'" id="a33"><button>&times;</button></span> </div> </div>

 function onToggle() { const ele = document.querySelector(".toggle-div"); ele.classList.toggle("toggle"); }
 body { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 100vh; }.button { position: relative; background-color: #4caf50; border: none; font-size: 28px; color: #ffffff; padding: 20px; width: 200px; text-align: center; -webkit-transition-duration: 0.4s; /* Safari */ transition-duration: 0.4s; text-decoration: none; overflow: hidden; cursor: pointer; }.toggle-div.toggle { visibility: hidden; }
 <body> <button onclick="onToggle()" class="button">Click here to toggle</button> <div class="toggle-div"> <h1>Toggle Div on click</h1> </div> </body>

暫無
暫無

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

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