Javascript controls the display and hide of the DIV layer.

Source: Internet
Author: User

If we want to use js to control the display and hiding of div, we can use js to control the style and define the display settings, in this way, you only need to set none and block dynamically to hide and display the div.

Simple pointing to text display content instance

The Code is as follows: Copy code

<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> oec2003 </title>
<Script language = "JavaScript" type = "text/JavaScript">
<! --
Function toggle (targetid ){
If (document. getElementById ){
Target = document. getElementById (targetid );
If (target. style. display = "block "){
Target. style. display = "none ";
} Else {
Target. style. display = "block ";
}
}
}
-->
</Script>
<Style type = "text/css">
<! --
# Div1 {
Background-color: #000000;
Height: 400px;
Width: 400px;
Display: none;
}
-->
</Style>
</Head>

<Body>
<Input type = "button" id = "butn" value = "show/hide" onclick = "toggle ('div1 ')"/>
<Center>
<Div id = "div1"> </div> </center>
Center DIV
</Body>
</Html>

Display images when connected

The Code is as follows: Copy code

<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN"
Http://www.w3.org/TR/html4/loose.dtd>
<Html>
<Head>
<Title> </title>
<Script type = "text/javascript">
Var path = './'; // relative path of the image
Function show (obj ){
Var name = obj. innerText;
Var sDiv = document. getElementById ('img _ '+ name. split ('. ') [0]); // determine the file name.
If (! SDiv ){
SDiv = document. createElement ("DIV ");
SDiv. id = 'img _ '+ name. split ('. ') [0];
SDiv. style. position = 'absolute ';
SDiv. style. top = obj. offsetTop + obj. offsetWidth + 'px ';
SDiv. style. left = obj. offsetLeft + obj. offsetHeight + 'px ';
SDiv. style. border = '1px red solid ';
Var img = document. createElement ("img ");
Img. src = path + name;
SDiv. appendChild (img );
Document. body. appendChild (sDiv );
}
SDiv. style. display = 'block ';
}
Function f (obj ){
Var name = obj. innerText;
Var sDiv = document. getElementById ('img _ '+ name. split ('. ') [0]); // determine the file name.
If (sDiv ){
SDiv. style. display = 'none ';
}
}
</Script>
</Head>
<Body>
<Div onmouseover = "show (this)" onmouseout = "f (this)" style = "position: absolute;">
Wait.gif
</Div>
</Body>
</Html>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.