Javascript dom programming (4): common objects 3, javascriptdom

Source: Internet
Author: User

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

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.