JS basic Window.document object operation and Common events!

Source: Internet
Author: User

I. Finding elements

  1.document.getelementbyid ("id"); Search by ID, find at most one.

var A=document.getelementbyid ("id"), put the found element in variable a.

2.getElementsByClassName () According to the class, find out the array.

3.getElementsByName () According to name, find out the array.

4.getElementsByTagName () based on the tag name, find out the array.

Two. Operation Contents

1. Non-form elements: for example var D=document.getelementsbyid ("a");

1. Get text: D.innertext only take the text inside!

2. Set the text: D.innertext=hello; The text inside will turn into hello.

3. Get HTML code: d.innerhtml gets all the tags and text that are set inside the D element!

4. Set HTML code:d.innerhtml=<b> bold text </b>.

2. Form elements

The value of the form element is

1. Assignment: D.value= "Assignment";

2. Get the value: Alert (d.value);

Three. Operation Properties

This is not a property, it is Method 1

1. Add attribute: D.setattribute ("attribute name", "Value of attribute");

2. Get Properties: D.getattribute ("attribute name");

3. Remove attribute: D.removeattribute ("attribute name");

Four. Operation Style

    Get the style in JS only get inline!

1.d.style. Follow the style that you want to manipulate in the style.

Five. Common events

Add return or FALSE to block the default action

OnClick: mouse click Trigger

OnDblClick: Double-click Trigger

Onmouserover: Trigger above mouse

Onmouserout: Mouse move out Trigger

Onmousermov: Mouse on top move is trigger

OnChange: As long as the content change is triggered

Onblur: triggers when losing focus

Onfocus: Triggers when focus is acquired

OnKeyDown: Triggered when the button is pressed

OnKeyUp: Triggered when the button is lifted

onkeypress: Event is triggered when the user presses and releases any alphanumeric keys.

JS basic Window.document object operation and Common events!

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.