Home >Web Front-end >JS Tutorial >JS controls hiding and display
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!