JavaScript Understanding and Classic case Analysis _javascript skills

Source: Internet
Author: User
Tags arithmetic arithmetic operators logical operators setinterval

Introduction to JS:

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

You can use JavaScript to easily make friendly welcome messages, beautiful digital clocks, happy lights with advertising effects, and easy elections, as well as display the time the browser stays. Let these special effects improve the visibility of the Web page.

JavaScript can now do a lot of things on the Web page, Web effects, Operation DOM,HTML5 games (based on HTML5 and JavaScript), animation and so on, but also to pull back the background data (through Ajax), not only can do the front desk can also do backstage,

such as Node.js, and so on, and some Desktop Engine Node-webkit can render JavaScript as a desktop application, where unity3d can use JavaScript to write games (Unity3d use JavaScript syntax, features, etc.)

Features of JavaScript language:

1). JavaScript is primarily used 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 script.

4). JavaScript is an interpretive language that performs side by side to explain.

JavaScript Knowledge Point Explanation:

1, operator

An operator is a sequence of symbols that completes an operation, with seven classes: assignment operators, arithmetic operators, comparison operators, logical operators, conditional operations, bitwise manipulation operators, and string operators.

2. Expression type

The combination of operators and operands, called expressions, is typically divided into four classes: assignment expressions, arithmetic expressions, Boolean expressions, and string expressions.

3, statements

A JavaScript program consists of several statements, which are instructions for writing a program. JavaScript provides a complete set of BASIC programming statements: If~else, assignment statements, switch selection statements, while loop statements, for loop statements, do while loops, break loops abort statements, and continue circular interrupt statements.

Note: At the time of judgment, only these 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, the value is true even when the argument is string "false"!

4. function

A function is a named segment of a sentence that can be used as a whole to draw off and execute. Use functions to note the following points:

1 functions are defined by the keyword function;

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

3 The function name is the name that is referenced when calling the function, it is sensitive to case, and cannot write the wrong function name when calling functions;

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

5 The Return statement returns the value of an expression, or it can not.

5. Object

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 a method for manipulating data in a property, called an object. For example, to set the background color of the Web page, the object is the document, the property name used is bgcolor, such as document.bgcolor= "Blue", that is to make the background color blue.

6. Events

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

7, variable

such as var myvariable = "some value";

Classic case:

JS Lottery

Included knowledge points: Use of Timer, Document object method use, JS array use, JS built-in object use, JS system function usage, registration event.

<! DOCTYPE html>  

Toggle the background picture

Included knowledge points: Use of timers, use of document object methods

<script type= "Text/javascript" >
        window.onload = function () {
      
      setinterval (step, 1000);
    var num = 1;
    function Step () {
      if (num < 5) {
        num++;
      } else {
        num = 1;
      }
      var dom = document.getElementById ("Imgid");
      Change its images src attribute
      dom.src = ' images/' + num + '. jpg ';
    }
   
  </script>
 
 

Happy lights:

Included knowledge points: Use of timers, use of document object methods, use of system functions, use of mouse events, use of node operations, circular 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) var opt = {};
          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): 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.SP Eed, function () {for (i = 1; I <= _this.line; i++) {_this.find ("Li:first"). Appendto (_t
              His); } _this.css ({margintop:0});
          });
          } _this.hover (function () {clearinterval (_this.timer);
          The function () {_this.timer = SetInterval (function () {_this.scrollup ();}, _this.timespan);
        }). Mouseout ();
})}) (JQuery); </script>  

JavaScript to understand, this is the case of JS will be put here. I hope I can help you!!!.

The above JavaScript understanding and classic case analysis is small series to share all the content, hope to give you a reference, but also hope that we support cloud habitat community.

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.