One: Body object manipulation
1. Concept
The body object is a member property of the Document object, accessed through Document.body.
Using the body object requires the body of the document to be created before it can be used, which means
The body of the document has not yet been created to access the body,
2.Body Common Properties:
AppendChild () Adding elements
RemoveChild () Delete element
getElementsByTagName () gets an array of objects through the HTML element name.
BgColor Document Background color
Backgorund Document Background Map
InnerText the text between an element
InnerHtml the HTML code between an element
The onload event is triggered when the document is loaded
OnUnload Event document is closed
onBeforeUnload Event document is triggered before closing
Two: The website advertisement case
<!doctype html>
<meta charset= "Utf-8" >
<title> Untitled Document </title>
<body>
<div id= "Div1" style= "left:100px; Position:absolute;
top:0px "></div>
<script language= "javascript" type= "Text/javascript" >
<!--
Move in the x-axis direction
var divx=1;
Move in the y-axis direction
var Divy=1;
Where to start the picture
The x-coordinate of the Var posx=0;//div
The y-coordinate of the Var posy=0;//div
function Move () {
Horizontal Ordinate plus 2
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 direction
Divx=-divx;
}
if (posy<=0| | Posy-div1.offsetheight*2>=document.body.clientheight) {
Divy=-divy;
}
}
Set timer
SetInterval ("Move ()", 10);
-
</script>
</body>
Copyright Notice: Bo Master original articles, reproduced please indicate the source. Http://blog.csdn.net/dzy21
JavaScript DOM Programming (4): Common Objects 3