2017-3-30 Window.document Object

Source: Internet
Author: User

1. Get Tagged Objects:

CSS: class, ID, Tag Selector <p><span>

JS: class, ID, tag Selector, name

2, JS found in the element:

document.getElementById (' id ');-Gets an object
Document.getelementsbyclassname (' class '); -Gets an array
document.getElementsByTagName (' mark '); -Gets an array as well
Document.getelementsbyname (' name '); -Gets an array as well

3, Master three events:

OnClick-click event
onmouseover-mouse Move-in event
onmouseout-Mouse Out event


4, control the style of the tag:
Tag object. style. style = "value";
Style "-" to delete, the first letter in the back becomes uppercase

On the right side of the equal sign, you can see the value of the inline style of the element.

JS, the object's Index property, you can record a value of type int

5. Operation Contents: (1) Non-form elements:

               Get content:alert (A.innertext); Just take the words inside

alert (a.innerhtml); Get content that includes the label itself

                setting Content:a.innerhtml= "<font color=red>hello word</font>";

A.innertext will present the things as they are,

Empty content: Assign an empty string

       (2) Form elements:

There are two ways of getting content:var a=document.f1.t1; Gets the input with ID t1 in the form form in ID F1;

var A=document.getelementbyid ("id"); get directly with ID;

alert (A.value); Gets the value in input;

alert (a.innerhtml); Get <textarea> value here </textarea>;

setting Content:a.value= "content change";

6. Operation Style and properties:

      Select Object : Var A=document.getelementbyid ("id");

      operation style : A.style. style = ""; Manipulate properties of this ID style

Styles are styles in CSS, and all styles can be manipulated in code.

document.body.style.backgrondcolor= "COLOR"; The background color of the entire window.

Action Style class:a.classname= "className in style sheet" action batch style

      Action Properties :a.setattribute ("attribute name", "attribute value"); Set a property, add or change all can;

           a.getattribute ("attribute name"); gets the value of the property

            a.removeattribute ("attribute name"); Remove an attribute

7. Timer:

window.settimeout ("code to execute", "time between milliseconds");
Time bomb, deferred execution, only once

window.setinterval (function () {}, Interval of time milliseconds);
Infinite loops, each cycle has a time interval, generally not less than 20 milliseconds
It has a return value and can use a variable to receive the Timer object.

Window.clearinterval (the timer object to be closed);
Once this code is executed, the execution of this timer object is stopped immediately.

      Window.cleartimeout (the object to be closed);

Clear delay

Object. offsetwidth

2017-3-30 Window.document Object

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.