Home > Web Front-end > JS Tutorial > body text

JS controls hiding and display

不言
Release: 2018-04-26 14:29:11
Original
1722 people have browsed it

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>
Copy after login

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";//显示
Copy after login


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="";//显示
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!