2016-09-27 76 views
1

頁面重新加載使用下面顯示的js函數來使頁面的一部分在用戶單擊按鈕時消失。當使用document.getElementById

但是當我點擊按鈕時,零件確實消失,但隨後頁面重新加載。 這是爲什麼呢?

<button id="myDIV" onclick="fncShowHide()">Try it</button> 

<script> 
window.fncShowHide = function() { 
    document.getElementById("idein").className = "display-none"; 
} 
</script> 
+0

'<按鈕類型= 「按鈕」 ID = 「myDIV」 的onclick = 「fncShowHide()」>嘗試' – Rayon

+0

是表單中的按鈕? – lustoykov

+1

@leo - 如果___NO___,會不會讓我們_quit_的發展.. – Rayon

回答

0

window.fncShowHide = function() { 
 
    document.getElementById("idein").className = "display-none"; 
 
} 
 

 
window.other_ = function() { 
 
    document.getElementById("idein").style.display = "none"; 
 
}
.display-none{ 
 
display:none; 
 
}
<button id="myDIV" onclick="fncShowHide(); return false;">Try it</button> 
 
<div id="idein">BYEEEEEEEEEEEEEEEEEEEEEEEEEEE!</div> 
 
<script> 
 

 
</script>

相關問題