JavaScript's understanding and classic case

Source: Internet
Author: User

Introduction to JS:

JavaScript is a programming language that makes your Web pages more lively, and is the easiest and most convenient language to design in your current Web page.

You can use JavaScript to easily make a friendly welcome message, a nice digital clock, an ad-effective marquee and a simple election, and also show the time your browser stays . Let these special effects improve the usability of your Web pages.

JavaScript can now do a lot of things on the Web page , Web effects, Operations DOM,HTML5 games (based on the combination of HTML5 and JavaScript), animation and other effects, but also to achieve pull back data (through Ajax), Not only can do the front desk can also do backstage,
such as node. js and so on, for example, some Desktop Engine Node-webkit can render JavaScript into desktop applications, such as Unity3d can use JavaScript to write games (Unity3d use of JavaScript syntax, features, etc.)

features of the JavaScript language:

1). JavaScript is used primarily to add interactive behavior to HTML pages.

2). JavaScript is a scripting language, and syntax is similar to Java .

3). JavaScript is typically used to write client-side scripts.

4). JavaScript is an interpreted language that performs edge interpretation.

JavaScript Knowledge Point Explanation:

1. Operators

An operator is a series of symbols that complete operations, which have seven classes: assignment operators, arithmetic operators, comparison operators, logical operators, conditional operations, bitwise manipulation operators, and string operators.

2. Expression

The combination of operators and operands is called an expression, usually divided into four classes: an assignment expression, an arithmetic expression, a Boolean expression, and a string expression.  

3. Statements

A JavaScript program is made up of several statements, which are instructions for writing a program. JavaScript provides complete BASIC programming statements: If~else, assignment statements, switch SELECT statements, while loop statements, for loop statements, do and loop statements, break loop abort statements, and continue loop interrupt statements.

Note: At the time of judgment, only these kinds of results are false:

If the logical object has no initial value or its value is 0,-0,null,"",false, undefined or NaN, the value of the object is false. Otherwise, its value is true, even when theargument is the string "false" !

4. Functions

A function is a named statement segment that can be used as a whole to be cited and executed. There are a few things to note about using functions:

1) functions are defined by the keyword function;

2) function must be defined before use, otherwise it will be an error;

3) The function name is the name that is referenced when the function is called, it is sensitive to case, and the function is not written in the wrong name when it is called;

4) The parameter represents the value passed to the function's use or operation, which can be a constant or a variable;

5) The return statement is used to return the value of an expression, or it may not.

5. Objects

An important function of JavaScript is the object-based function, which can be developed in a more intuitive, modular and reusable way through object-based programming. A set of properties that contain data and methods that manipulate the data in a property, called an object. For example, to set the background color of the page, the object is the document, the property name used is bgcolor, such as document.bgcolor= "Blue", that is, the color of the background is blue.

6. Events

The action that occurs when a user interacts with a Web page, called an event. Most things are triggered by the user's actions, such as: the user presses the mouse button, generates the OnClick event, if the mouse pointer moves on the link, generates onmouseover events and so on. In JavaScript, events are often used in support of event handlers.

7. Variables

such as var myvariable = "Some value";

Classic case:

JS Draw

The knowledge points include: Use of timer, use of document object, JS array, use of JS built-in object, use of JS system function, register event.

<! DOCTYPE html>varAllData = "A,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z"varAlldataarr = Alldata.split (","); varnum = alldataarr.length-1; vartimer; functionstart () {clearinterval (timer); h Timer= SetInterval (' Change () ', 10); }        functionChange () {document.getElementById ("Oknum"). InnerHTML = Alldataarr[getrnd (0, num)]; }        functiongetrnd (min, max) {returnparseint (Math.random () * (Max-min + 1)); }             functionok () {clearinterval (timer); document.getElementById ("Showresult"). Value = document.getElementById ("Oknum")). InnerText; }      </script> your choices are:<input type= "text" id= "Showresult" value= "/></body>

Background image switching

Included knowledge points: Use of timers, methods of document objects

<script type= "Text/javascript" >window.onload=function() {setinterval (step,1000); }        varnum = 1; functionStep () {if(Num < 5) {num++; } Else{num= 1; }            varDom = document.getElementById ("Imgid"); //change the src attribute of it imagesDOM.SRC = ' images/' + num + '. jpg '; }          </script>

Marquee:

Knowledge points included: Use of timers, use of methods of document objects, use of system functions, use of mouse events, use of node operations, looping statements, judgment statements

<script src= "Js/jquery-1.8.3.min.js" ></script> <script type= "Text/javascript" >                 ( function($) {$.fn.extend ({rolltitle:function(OPT, callback) {if(!opt)varopt = {}; var_this = This; _this.timer=NULL; _this.lineh= _this.find ("Li:first"). Height (); _this.line= Opt.line? parseint (Opt.line): parseint (_this.height ()/_this.lineh, 10); _this.speed= Opt.speed? parseint (Opt.speed, 10): 3000, _this.timespan= Opt.timespan? parseint (Opt.timespan, 13): 5000; if(_this.line = = 0) This. line = 1; _this.upheight= 0-_this.line *_this.lineh; _this.scrollup=function() {_this.animate ({margintop: _this.upheight }, _this.speed,function () {                             for(i = 1; I <= _this.line; i++) {_this.find ("Li:first"). AppendTo (_this); } _this.css ({margintop:0 });                    }); } _this.hover (function() {clearinterval (_this.timer); }, function() {_this.timer= SetInterval (function() {_this.scrollup ();}, _this.timespan);                }). Mouseout (); })}) (jQuery);</script>functionTest () {$ ("#RunTopic"). Find ("Li:first"). AppendTo ($ ("#RunTopic")); }       </script> </body>

JavaScript understanding, it is here, after the case of JS will be put here. Hope to be able to everyone!!!

JavaScript's understanding and classic case

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.