JavaScript Learning Summary

Source: Internet
Author: User
Tags object object tag name

One: Objects in JavaScript

Divided into 3 kinds.

1.JavaScript Built-in objects

Commonly used have Date,array,string,math, objects, these are often used, must be mastered well.

2. Document Object Model (MODEL,DOM)

This object represents multiple components of the current browser and the current HTML document.

3. Custom Objects

II: DOM object, History and location

To manipulate browsers and documents, JS uses hierarchical parent objects and sub-objects, which is the DOM. These objects are organized like a tree structure and represent all the content components of a Web document.

Window is the parent object of all objects

Several common methods of document object Object
document. URL: Indicates the URL address of the document. Cannot be changed, if need to give the user different address should use window.location Object
document.write: Lists the title of the current page
document.referrer: The URL address of the previous page that the user is viewing. document.lastmodified: Document Last Modified date
Document.cookie allows you to read and set a cookie for a document

Several common methods of history object object

History.length (); Saves the length of the history list
History.go (); open a URL in the history list to specify a positive or negative number.  History.back (); the previous URL in the History list is equivalent to a back button. Historay.forward (); The last URL in the History list is equivalent to the back button.

Several common methods of location object
Location.protocol: protocol part of URL---http
Location.hostname: Host name of URL---www.aaa.com location.port: port number of URL---80
Location.pathname: The filename portion of the URL---tese.do location.search: The query portion of the URL---lines=1 location.hash: The anchor name used in the URL---#anchor Two methods for location objects
Location.reload () Refreshes the current document, the Refresh button in the browser. Location.replace () to replace a new location

Three: Using the event object in JavaScript

If you use the event object, you can pass it to the handler function.

1.event.button: Press the mouse button. For the left mouse button, the property value is 1, for the right mouse button, the property value is

2.EVENT.CLIENTX: x-coordinate (column, in pixels) of the location where the event occurred

3.event.clienty: The y-coordinate of the location of the occurrence of the event (row, in pixels)

4.event.altkey: This flag indicates whether the ALT key is pressed when an event occurs

5.event.ctrlkey: This flag indicates whether the CTRL key is pressed when the event occurs

6.event.shiftkey: This flag indicates whether the SHIFT key is pressed when the event occurs

7.event.keycode: Key code (expressed in Unicode) of the key

8.event.srcelement: The object that the element appears in

Several functions in mouse events (they all belong to the Document object)

1.onMouseOver: Called when the mouse pointer moves over the link

2.onMouseOut: Called when the mouse moves out of the edge of the object
3.onMouseMove: As long as the mouse moves, it will be triggered (browser in, by default, not supported, need to use event capture technology)
4.onClick: When the mouse button is clicked, if the OnClick event handler returns false, the link is not opened (if the object is a link)

Four: Using forms to get data in JavaScript

Javascript Form Object
Name returns the names of the forms, that is, <form name= "..." > Properties.
Action Returns/sets the submission address of the form, which is <form action= "..." > Properties.

method returns/sets the way the form is submitted, that is, <form method= "..." > Properties.

Target Returns/sets the window returned after the form is submitted, that is, <form target= "..." > Properties.

Encoding Returns/sets the encoding of the form submission, that is, <form enctype= "..." > Properties.

Length returns the number of elements contained in this form.

Method
Reset () resets the form. This is the same as pressing the "Reset" button.

Submit () Submission form. This is the same as pressing the "Submit" button.

Event
OnReset; OnSubmit

V: The DOM of the Consortium

Accessing nodes in the DOM
ParentNode (). This method can access the parent node.
FirstChild (). This method can access the node's first child node, which does not exist to return null.

NextSibling (). This method can access the next sibling node, and returns null if it does not exist.

PreviousSibling ().  This method can access the previous sibling node, and returns null if it does not exist. Document methods
getElementsByTagName (elementname): Gets a list of all the elements that have the name in the file or in a certain part of the file, and creates such a nodelist to access the named nodes through the index.
CreateElement () method: The tag name of the new element is used as an argument, and the element object created can accept the attribute and value.
Createdocumentfragment () Method: Create a DocumentFragment node.

createTextNode (), Createcomment (), and Createcdatasection () methods: Create the nodes as they are named, and their arguments become the strings of the node contents

  

JavaScript Learning Summary

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.