Javascript dom programming (4): common objects 3, javascriptdom
I. body object operations
1. Concept
The body object is a member attribute of the document Object. It is accessed through document. body.
To use a body object, you must create a document subject before using it.
Access the body if the document body has not been created,
2. Common attributes of the Body:
AppendChild () add element
RemoveChild () deletes an element.
GetElementsByTagName () obtains the object array by using the html element name.
BgColor document background color
Backgorund document background image
InnerText text between an element
InnerHtml html code for an element
Onload event document is triggered when loaded
Triggered when the onunload Event document is disabled
Triggered before the onbeforeunload event is disabled
Ii. web advertisement bar case
<! Doctype html>
<Html>
<Head>
<Meta charset = "UTF-8">
<Title> untitled document </title>
</Head>
<Body>
<Div id = "div1" style = "LEFT: 100px; POSITION: absolute;
TOP: 0px "> </div>
<Script language = "javascript" type = "text/javascript">
<! --
// Move to the X axis
Var divX = 1;
// Move to Y axis
Var divY = 1;
// Start Image Position
Var posX = 0; // The x coordinate of the div
Var posY = 0; // y coordinate of div
Function move (){
// Add 2 to the horizontal and vertical coordinates
PosX + = 2 * divX;
PosY + = 2 * divY;
Div1.style. top = posY + "px ";
Div1.style. left = posX + "px ";
If (posX <= 0 | posX + div1.offsetWidth> = document. body. clientWidth ){
// Change the direction
DivX =-divX;
}
If (posY <= 0 | posY-div1.offsetHeight * 2> = document. body. clientHeight ){
DivY =-divY;
}
}
// Set the timer
SetInterval ("move ()", 10 );
// -->
</Script>
</Body>
</Html>
Copyright statement: original post of the blogger. For details, refer to the source. Http://blog.csdn.net/dzy21