[英]How do I hide this paragraph tag?
我對這一切都比較陌生,但是我學得很快,因為我認為這很容易。 我試圖使一個按鈕隱藏另一個按鈕產生的<p>
標簽。 如何使按鈕(位於代碼底部)使<p>
標記消失?
<button type="button" onclick="document.getElementById('date_button').innerHTML = Date()"> Click this button to display the current time!</button><br> <p id="date_button"></p><br><br> <button onclick="myFuction()">Click this to hide date.</button>
您必須定義被調用的函數並使用display:none隱藏段落
function myFuction() { document.getElementById('date_button').style.display = 'none' }
<button type="button" onclick="document.getElementById('date_button').innerHTML = Date();document.getElementById('date_button').style.display='block'"> Click this button to display the current time!</button><br> <p id="date_button"></p><br><br> <button onclick="myFuction()">Click this to hide date.</button>
嘗試這個。 我認為這可以幫助
function myFuction() {
document.getElementById('date_button').style.display = 'none';
}
在您的情況下,您想再次顯示它,因此需要將其innerHTML
設置為''
。 就您而言,如果要執行style.display = 'none'
。 它不會再次顯示<p>
function myFunction(){ document.getElementById('date_button').innerHTML = ''; }
<button type="button" onclick="document.getElementById('date_button').innerHTML = Date()"> Click this button to display the current time!</button><br> <p id="date_button"></p><br><br> <button onclick="myFunction()">Click this to hide date.</button>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.