Home >Web Front-end >JS Tutorial >JS controls hiding and display

JS controls hiding and display

不言
不言Original
2018-04-26 14:29:111779browse

This article shares with you a relatively simple JS code for controlling hidden display. Friends in need can take a look.

It is a relatively simple implementation. style.display is to control the hiding of the layer. Or the displayed attribute.

<html>
<body>
<script>
function show(){
document.getElementById("p").style.display="";
//alert(document.getElementById("p").style.display)
}
function hidden(){
document.get
ElementById("p").style.display="none";
//alert(document.getElementById("p").style.display)
}
</script>
<BODY>
<input name="name" type="button" onClick="show();" value="显示">
<p id="p" style="display: none" onMouseout="hidden();">
show it
</p>
</BODY>
</HTML>

p'svisibility can control the display and hiding of p, but after hiding, the page will appear blank

style="visibility: none;"
document.getElementById("typep1").style.visibility="hidden";//隐藏
document.getElementById("typep1").style.visibility="visible";//显示


By setting the display attribute, you can release the occupied page space after p is hidden , as follows

style="display: none;"
document.getElementById("typep1").style.display="none";//隐藏
document.getElementById("typep1").style.display="";//显示

If you use p.style.display="none" to hide it, things in p will sleep and the events inside will not respond.




The above is the detailed content of JS controls hiding and display. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn