JavaScript notes (01)

Source: Internet
Author: User
Tags arithmetic operators script tag

--------------------JavaScript Basics
1. How to embed the page
1. Inter-row events (mainly for events):
<input type= "button" Name= "onclick=" alert (' ok! ‘);" >
2, page script tag embedding:
<script type= "Text/javascript" >
var a = ' Hello! ‘;
alert (a);
</script>
3. External introduction:
<script type= "Text/javascript" src= "Js/index.js" ></script>


2. Variable type
1, 5 kinds of basic data types:
Number, String, Boolean, Undefined, null

2, 1 kinds of composite types:
Object

3, variables, functions, attributes, function parameter naming specification
1. Case-sensitive
2. The first character must be a letter, an underscore (_), or a dollar sign ($)
3. Other characters can be letters, underscores, dollar symbols, or numbers

3. Pre-parsing of variables and functions
The JavaScript parsing process is divided into two phases, first in the compilation phase, then in the execution phase, in advance of function-defined functions in the compile phase, and the variable declaration defined by Var is advanced, assigning it to undefined.

4. Operators
1. Arithmetic operators: + (plus),-(minus), * (multiply),/(except),% (for redundancy)
2. Assignment operators: =, + =,-=, *=,/=,%=
3. Conditional operators: = =, = = =, >, >=, <, <=,! =, && (and), | | (OR),! No


--------------------javascript_ arrays and how to operate them
1. Methods for defining arrays
Instance creation of an object
var = new Array (alist);

Direct Volume creation
var = [AList2, ' ASD '];

2. How to manipulate data in an array
1, get the length of the array: alist.length;
var alist = [1,2,3,4];
alert (alist.length); Pop Up 4
2. Use subscript to manipulate an array of data: alist[0];
var alist = [1,2,3,4];
Alert (alist[0]); Pop up 1
3. Join () merges the array member into a string by a delimiter
var alist = [1,2,3,4];
Alert (Alist.join ('-')); Eject 1-2-3-4
4. Push () and pop () add or remove members from the last array
var alist = [1,2,3,4];
Alist.push (5);
alert (alist); Eject 1,2,3,4,5
Alist.pop ();
alert (alist); Eject 1,2,3,4
5, Unshift (), and Shift () Add or remove members from the front of the array
var alist = [1,2,3,4];
Alist.unshift (5);
alert (alist); Eject 5,1,2,3,4
Alist.shift ();
alert (alist); Eject 1,2,3,4
6. Reverse () reverses the array
var alist = [1,2,3,4];
Alist.reverse ();
alert (alist); Eject 4,3,2,1
7, IndexOf () returns the index value of the first occurrence of an element in an array
var alist = [1,2,3,4,1,3,4];
Alert (Alist.indexof (1));
8. Splice () Add or remove members from the array
var alist = [1,2,3,4];
Alist.splice (2,1,7,8,9); Starting with the 2nd element, delete 1 elements, then add ' 7,8,9 ' three elements at this position
alert (alist); Eject 1,2,7,8,9,4
3. Multidimensional arrays
A multidimensional array is a member of an array and an array of arrays.
var alist = [[1,2,3],[' A ', ' B ', ' C '];
Alert (alist[0][1]); Eject 2;


--------------------Javascript_ String Manipulation methods
1. String merge operation: "+"
2. parseint (): Converts a numeric string to an integer
3. Parsefloat (): Converts a numeric string to a decimal number
4. Split (): Separates a string into an array of strings
5, CharAt (): Gets a character in a string
6, IndexOf (): Find whether a string contains a character
7, SUBSTRING (): Intercept string usage: substring (start,end) (not including end)
8, toUpperCase (): String to uppercase
9, toLowerCase (): String to lowercase


--------------------Javascript_ Timer
1, setTimeout only the timer to execute once
2. Cleartimeout off the timer that only executes once
3, SetInterval repeated execution of the timer
4, Clearinterval Close the timer of repeated execution

JavaScript notes (01)

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.