Basic Javascript Tutorial: switch statement. Basic Tutorial: switch
The format of the stwith statement is generally as follows:
Copy codeThe Code is as follows:Switch (expression ){Case value: statement1Break;Case value2: statement2Break;....Case value: statementBreak;Default: statement;
If expression is equal to case,
Commas are also legal in JavaScript statements, which represent the sequential execution of statements that, using it, can be used to line up several statements to a compressed file size. Because of the poor readability of this writing, it is generally found in compressed JavaScript.As the following example from a compressed file, through the format, you can find that the loop statement can be combined with
4: when the user clicks the "select" tab, that is, the div. We use a div to move it to the bottom of a div. This is the replacement of options.
This is basically the case. Next we will implement it step by step!
[Preparations]1. Think about how you want to beautify the SELECT statement and prepare the corresponding image. I have prepared two small pictures, that is, drop-down arrow 1 and drop-down arrow 2 are the default style, and 2 are the styl
1. Eventsonmousedown--Mouse Down EventsWhen the mouse button is triggered, depending on the mouse button will have different values passed in, left button 0, wheel 1, right button 2, different browsers may be different.onmousemove--triggers when the mouse movesonkeydown--when keyboard keys are triggered2. Element coordinatesThe offset relative to the event source object, which is the element coordinate, relative coordinateConsole.log (event.offsetx+ ', ' +event.offsety)The location of the viewab
var d = new Date ();//create Current Date Objectvar d = new Date (' 2016/03/22 ');//Allowvar d = new Date (' 2016/3/22 ');//Allowvar d = new Date (' 2016-3-22 ');//invalidvar d = new Date (' 2016-03-22 ');//AllowD.setfullyear (2010);//Set yearAlert (D.getfullyear ());//Get YearD.setmonth (5);//Set monthAlert (D.getmonth ());//Get month. 0 means January, 1 means February, 2 means March ...D.setdate (10);//Set DayAlert (D.getdate ());//Acquisition DayAlert (D.getday ());//Get week. 0 means Sunday,
Town Field Poem:The Pure Heart sentiment wisdom language, does not have the world name and the benefit. Learn water under the hundred rivers, give up arrogant slow meaning.Learn to have a small return to feed root, willing to cast a conscience blog. Sincere in this writing experience, willing to see the text to inspire.——————————————————————————————————————————Code1 DOCTYPE HTML>2 HTML>3 Head>4 Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"/>5 title>title>6 Scriptt
("string Error"); -}Looping statements1 for (var a=0;aa=a+1) {2 if (a==5) { 3 continue; 4 }5 alert (a); 6 }The output is removed from 0-9 except 5.Instance Application1 //write out the odd number within 100 2 var str= ""; 3 for (Var a=1;aa++) {4 if (a%2! =0) {5 str=str+a+ ","; 6 }7}8alert (str);1 //Beg 1+2+3+4+ ... 10 and 2var sum=0; 3 for (Var a=1;aone; a++) {4 sum=sum+a; 5 }6alert (sum);1 //ask for factorial of 1-10 2 var sum=1; 3 for (Var a=1;aone; a++)
can only jump out of the inner K Loop, and the J Loop will go on. There are a lot of unnecessary loops. We hope that, when found, jump directly outside the J Loop and start looking for the next ID. At this point, we need to use the label. The code is as follows: for(vari=0;i) {outpoint: for(varj=0;j){ for(vark=0;k){ if(All[j][k].id = =Itemsid[i]) {Console.log (all[j][k]); BreakOutpoint; } } }}//in this way, when all[j][k].id = = Itemsid[i], you will
separate integer types, so 1 and 1.0 are the same values.This provides great convenience because it completely avoids the problem of the overflow of short integers, and all you need to know about numbers is that it is a number.This avoids a large class of errors caused by a numeric type.If a number literal has an exponential part, then the value of this literal is calculated by multiplying the portion of the previous part of E by the part of the e that follows 10. So 100 and 1e2 are the same nu
If is one of the common syntax, the format is as follows
if (Coditon) statement1 (Else Statement2)
Where Coditon can be any expression, not even a true Boolean value, because JavaScript converts it automatically to a Boolean value.
Executes statement1 if the condition execution evaluates to TRUE, and executes the result Statment2 if the condition is false (else is not required if statement2 exists)
Each conditional
)? Alert ("success!"): Alert ("failure!");
So if you have more than one code to execute, you should use an anonymous function. Such as:
(xmlhttprequest.readystate==4 xmlhttprequest.status ==200)? function () {alert ("success!"); var a=100; alert (a);: Alert ("failure!");
In the jquery 1.7.1 source code These two shorthand forms are too many, as line 2643 has:
Hook for boolean attributes
Boolhook = {
get:function (elem, name) {
//Align Boolean attributes with Cor
In writing a program, there may be a situation when you need to take a path out of a given two paths. Therefore, you need to use conditional statements to let programs make the right decisions and perform the right actions.
JavaScript supports its use to perform operating condition statements that differ according to different conditions. Here, we will explain if. Else statement.
Learning to parse the JSON string today, using an eval () method, why do I need parentheses when parsing a string? I can't touch my head. The original JavaScript {} statement block is ambiguous, without parentheses there will be errors, understanding this ambiguity is very helpful for us to understand JavaScript code.
Two meanings of one, {}
The break statement is used to jump out of a loop.The Continue is used to skip an iteration in the loop.Break statementWe have seen the break statement. It is used to jump out of a switch () statement.The break statement can be used to jump out of a loop.After the break statement jumps out of the loop, the code after t
JavaScript has a with keyword, and the original intent of the WITH statement is to provide a namespace-style sketching method for hierarchical object access. That is, the object is called directly through the node name in the specified code area.The function of the WITH statement is to temporarily change the scope chain and reduce the repeated input.Its syntax st
Core tips: JavaScript Conditional Statement If ... Else
When you write code, you often need to perform different behaviors according to different conditions. You can use conditional statements in your code to accomplish this task.
In JavaScript, we can use the following conditional statements:
If statement
(Deleteobj.one) + "document.write ("Delete element is succeed:" + (delete deleteobj) + "document.write ("Delete defined x:" + (delete x) + "var x = 1;
The above reflects the delete, can delete the object's properties, variables, cannot delete objects, undefined variables.
javascript: statement1, If,else if statement
Because it is the basic statement,
A brief description of the JavaScript return statement:The return statement is very important in JS, not only has the function of returning function value, but also has some special usage, it is very necessary to have a clear grasp. The following is a simple introduction to the role of the return statement in conjunction with the example.A. Used to return control
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.