JavaScript DOM Programming (4): Common Objects 3

Source: Internet
Author: User

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

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.