javascript-Rotten Pen

Source: Internet
Author: User
Tags tag name

JavaScript

Sensitive to case
Comment Line with://
Notes for multi-sweat:/* */
Declaring variables: var variable name (variable declared with no value, value undefined)
JavaScript variables are objects
You can use the keyword "new" to declare its type
var name = new String;
var x = new number;
var y = new Boolean;
var cars = new Array;
var object = new Object;
Variable Assignment: =
Data type: String, Number, Boolean, array, object, Null, Undefined
var a= ' a '; var b=2.01;var c=true;
var d=new Array ("Zu1", "Zu2", "ZU3");
The array subscript is based on the 0 start
var object={firstname: "Bill", LastName: "Gates", id=5566}
There are two ways to address object properties: Name=object.firstname or name=object["LastName"]
JavaScript function Syntax:
function functionname () {
The code to execute
}
function with parameters and return merit
function functionname (VAR1,VAR2) {
The code to execute
Return the value to be returned
}
JavaScript variables:
The lifetime of JavaScript variables begins at the time they are declared.
Local variables are deleted after the function is run.
Global variables are deleted after the page is closed.
Operator:
Assignment: =
Arithmetic operator: +-*/% + +--
Comparison operators: = = = = = = = = = = = = = = = = = = = > < >= <=
Logical operator:&& | | !
Conditional operator: syntax-variablename= (condition)? value1:value2
Conditional statements:
If statement:
if (condition) {
Code executed when the condition is true
}
If...else statement:
if (condition) {
Code executed when the condition is true
}else {
Code executed when the condition is false
}
If...else If...else Statement:
if (condition 1) {
Code executed when condition 1 is true
}else if (condition 2) {
Code executed when condition 2 is true
}else {
Code that executes when condition 1 and condition 2 are not true
}
Switch statement:
Switch (n) {
Case 1:
Executing code block 1
Break
Case 2:
Executing code block 2
Break
Default
Code to execute when a match does not exist
}
Different types of loops:
For-loop code block for a certain number of times
For/in-Looping through the properties of an object
While-loop the specified block of code
Do/while-Loop the specified block of code
Break: Jump out of the loop
Continue: Skips an iteration in a loop
To find HTML elements:
by Id:document.getElementById ("Idname")
By tag name: Document.getelementbytagname ("TagName");
By class name:
To change the contents of HTML:
document.getElementById ("Idname"). InnerHTML = new HTML
To change the properties of HTML:
document.getElementById ("Idname"). Attribute = new value
If you change the picture:<script>
document.getElementById ("image"). src= "Landscape.jpg";
</script>
To change the style of HTML:
document.getElementById ("Idname"). Style.property = new Style
If you change the color:
<script>
document.getElementById ("P2"). style.color= "Blue";
</script>





javascript-Rotten Pen

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.