Javascript Note 1: javascript note
1. Operate HTML elements
To access an HTML element from JavaScript, you can use the document. getElementById (id) method.
Use the "id" attribute to identify HTML elements:
Example:
Use the specified id to access the HTML element and change its content:
<!DOCTYPE html>
Output result:
My First Web PageMy First JavaScript
2. Array
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. Object (the object is only a special data type with attributes and methods)
An attribute is a value related to an object. The method is an action that can be executed on an object.
Objects are separated by curly brackets. Within the brackets, the attributes of an 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 preceding example has three attributes: firstname, lastname, and id.
Spaces and lines do not matter. The statement can span multiple rows:
var person={firstname : "Bill",lastname : "Gates",id : 5566};
4. Declare the variable type
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 all objects. When you declare a variable, a new object is created.
Note:
All things in JavaScript are objects: strings, numbers, arrays, dates, and so on.
In JavaScript, objects are data with properties and methods.
5. attributes and Methods
An attribute is an object-related value.
A method is an action that can be executed on an object.
For example, cars are objects in real life.
Attributes of a car:
car.name=Fiatcar.model=500car.weight=850kgcar.color=white
Car methods:
car.start()car.drive()car.brake()
The attributes of a car include name, model, weight, and color.
All cars have these attributes, but each car has different attributes.
A car can be started, driven, or braked.
All cars have these methods, but they are executed at different times.
6. Labels
As you can see in the switch statement chapter, you can mark JavaScript statements.
To mark a JavaScript statement, add a colon Before the statement:
BMWVolvoSaab
7,
Who has javascript study notes? Send me one.
Download the learning Manual Online! Baidu search: javascript manual download
I recommend a book to learn JavaScript,
Recommended books for beginners: JavaScript DOM programming Art
My js started from this book and read it three times before and after. The book is simple, easy to learn, easy to learn, and rigorous in programming. A good entry book will have a profound impact on your future programming. This book has never lived up to this historical mission.
Basic learning books: JavaScript authoritative guide
The JavaScript authoritative guide describes various functions and features of JavaScript in detail. You can skip this section for reference on about 500 pages (JavaScript core reference, client JavaScript reference, and DOM reference.
Advanced promotion books: JavaScript Advanced Programming
Emphasize the concept of OPP ideologically, focus on practicality in content, and learn more and more detailed knowledge from it, and pay attention to the solution of browser differences.
But if you want to read it, you must have a certain degree of JavaScript Foundation (or read the first two books). Otherwise, it will bring a sense of frustration and enthusiasm for learning.
I personally feel that, instead of reading a few general books, it is better to read one book intensively. The art of JavaScript DOM programming is the first choice.