Javascript Learning Notes One

Source: Internet
Author: User

1. Manipulating HTML elements
If you want to access an HTML element from JavaScript, you can use the document.getElementById (ID) method.
Use the ID property to identify the HTML element:
Example:
Access the HTML element with the specified ID and change its contents:

<! DOCTYPE html>

2. Arrays

The following code creates an array named cars:

var cars=new Array (); cars[0]= "Audi"; cars[1]= "BMW"; cars[2]= "Volvo";
or (condensed array):
var cars=new Array ("Audi", "BMW", "Volvo");

3. Objects

Objects are separated by curly braces. Inside the parentheses, the properties of the object are defined in the form of name and value pairs (name:value). Attributes are separated by commas:

var person={firstname: "Bill", LastName: "Gates", id:5566};
The object (person) in the example above has three attributes: FirstName, LastName, and ID.
Spaces and lines do not matter. Declarations can span multiple lines:
var person={firstname: "Bill", LastName  : "Gates", id        :  5566};

4. Declaring variable types

When you declare a new variable, you can use the keyword "new" to declare its type:

var carname=new string;var x=      new Number;var y=      new Boolean;var cars=   new Array;var person= new Object;

JavaScript variables are objects. When you declare a variable, a new object is created.

Small bet

All things in JavaScript are objects: strings, numbers, arrays, dates, and so on.
In JavaScript, objects are data that owns properties and methods.

5. Properties and Methods

A property is a value associated with an object.
Method is an action that can be performed on an object.
For example, a car is a real-life object.
Properties of the car:

Method of Car:

Car.start () car.drive () Car.brake ()
The properties of the car include name, model, weight, color, etc.
All cars have these properties, but the properties of each car are different.
The method of car can be start, drive, brake and so on.
All cars have these methods, but they are executed in different times.

6. Label

As you saw in the switch statement chapter, you can tag JavaScript statements.
To mark a JavaScript statement, precede the statement with a colon:

Break Labelname;continue LabelName;






Javascript Learning Notes One

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.