Back to Catalog
Objective
Before you say jquery, learn the basics of JavaScript (hereafter referred to as JS) in a language that has the same basic knowledge for every programming language, variable, function, conditional statement block, loop block, and so on, and for each language, it seems to be different in the way it is written. , such as JS in the definition of variables, you want to use VAR departing tone local variable declaration, and for the weak type of the language JS, you can also not add Var, but do not add it will think that this variable is a global variable, this is to pay attention to.
Variable
The value of the program can change during the course of running (hehe, the definition of the book more than 10 years ago)
declare a variable named people var people="Good boy//Declare a variable and assign it to it, the browser automatically interprets it as a character variable var age=// Declare a local variable, type age=// Declare a global variable, type is shaping, and it will not be released during program execution
Function
In order to implement a function, some blocks of code are organized together to form a whole, we call it function functions, which can greatly reduce the amount of code duplication and make the program clearer
//Standard notationFunciton Hellofun () {alert ( "hellow world" )} //var Hellofun=function () {alert ( " hellow world)} // function can have parameters, which are different from weakly typed var hellofun=function (msg) {alert (msg);} //" Span style= "color: #800000;" >hello world
Conditional statements
For one thing, there are a number of results, then the conditional statement on the appearance, if the condition fixed a few values, you can use switch, otherwise using If...else, see the code
//Switch instancevar Inputnumber=document.getelementbyid ("Type"). Value;Switch(Inputnumber) {Case1: Alert ("Type No. 1th");Break;Case2: Alert ("Type No. 2nd");Break;Case3: Alert ("Type No. 3rd");Break;Default: Alert ("throw new Exception ()");Break;}//If instancevar Inputage=document.getelementbyid ("Age"). Value;if (inputage>1 && inputage<18) {alert ("Minor");}else if (Inputage>= && inputage<70 " adult ); else if (Inputage>= 70 old man ""}else{Alert ( " fill out the form in error "
Looping statements
That is, when we echo a certain condition, we execute a block of code repeatedly, we can use while, for and so on.
for Loop var arr=[1,2,3] for(var i=0,j=arr.length;i<j;i++// The console of Firefox can see the results}
In fact, in the JS World, for code execution performance is also very fastidious, we in the For statement performance is not wrong, but if written below, performance will be reduced, because it every time
When traversing, the length of arr is to be obtained.
for Loop var arr=[1,2,3]for (var i=0;i<arr.length;i++// Bad performance}
Well, for the basic knowledge of JS programming is written here, from the next start, will introduce the relevant knowledge of jquery, thank you for reading!
Back to Catalog
jquery is really not hard ~ First time programming Basics