Basic JavaScript tutorial [warm know new one]

Source: Internet
Author: User
Tags local time

The son said: "Wen so know new, can for the teacher." Confucius said: "Brush up on old knowledge to learn new understanding and experience, with this point can become a teacher." "In particular, we have a program, whether it is a full stack of engineers, are set terrorize in one." But sometimes some knowledge if there is a long time useless, will forget, even forget you do not remember, especially some basic things. So I'm going to write a "warm so know new" series of blog post out, one of these basic things I am relatively forgetful, later to facilitate their own page, and the hope can help some of the newly-started friends. All of the knowledge points recorded in this series are the most (important things to say three times) basic knowledge. Most of the notes I have accumulated while studying.

temperature so that the new series are some basic knowledge, the great God can skip directly.

vWrite in front

If the terrorize are all mastery, if any weapon you are playing with a kind of model, then this blog post you can skip. Just when you forget, you can take it out and brush it up.

vBasic concepts

JavaScript is a literal-translation scripting language, which is a dynamic type, a weak type, a prototype-based language, and a built-in support type. Its interpreter, known as the JavaScript engine, is widely used as a scripting language for the client, and is used in HTML (an application under the standard Universal Markup Language) to add dynamic functionality to an HTML Web page.

In a nutshell: JavaScript is an object-based, drive-event, security-and-weak-type scripting language.

1. Declaring variable keyword: var

2. Name of the variable:

    • Consists of numbers, letters, underscores, and $
    • Number cannot start
    • Strictly case-sensitive
    • cannot be named with a keyword

3. Data type:

    • Basic data types
      • numeric types (shaping and floating-point)
      • String type
      • Boolean type
    • Reference (composite) data type
      • Functions: Function ()
      • Objects: Object ()
    • Special Data type undefined

4. Method of detecting data type: typeof ()

5. Operator Precedence: () >!> arithmetic > Relationship >&&>| | > Conditions > Assignment

6. Type Conversion Mode:

    • parseint () is converting a string type to an integer
    • Parsefloat () is the conversion of a string type to a float type
    • NaN is not a number
vfunction Introduction

1. Function definition: a function (also called a method) is used to categorize a piece of code to achieve a certain purpose so that it is not more organized.

2. The life of the function:

function name ([parameter 1],[parameter 2],...)

{

Code module

}

3. Timer: setinterval ("function name", Time ms) PS: This detailed section is below

4. System functions:

  • Date function
    • GetYear (): Can return a two-bit or four-bit number representing the year

      <script type= "Text/javascript" >varnew  Date () document.write (D.getyear ())</ Script>
    • GetMonth (): Can return a number that represents a month

      <script type= "Text/javascript" >var d=New  Date () document.write (D.getmonth ())/ /  Month is starting from 0 </script>
    • GetDate (): Can return a day of the month

      <script type= "Text/javascript" >varnew  Date () document.write (D.getdate ())</ Script>
    • toLocaleString (): Converts a Date object to a string based on local time and returns the result

      <script type= "Text/javascript" >varnew  Date () document.write (d.tolocalestring ()) </script>
  • Math Object
    • Abs (): The absolute value of the number of returns

       <script type= "Text/javascript" >document.write (Math.Abs ( 7.25) + "<br/>") // 7.5  document.write (Math.Abs ( -7.25) + "<br/>") // 7.25  document.write (Math.Abs (7.25-10)) // 2.75  </script> 
    • Round (): A number can be rounded to the nearest integer

       <script type= "Text/javascript" > 0.60) + "<br/>") // 1  document.write (Math.Round (0.50) + "<br/>") // 1  document.write (Math.Round (0.49) + "<br/>") // 0  document.write (Math.Round ( -4.40) + "<br/>") // -4  document.write (Math.Round ( -4.60)) // -5  </script> 
    • Random (): You can return a random number between 0 and 1

       <script type= "Text/javascript" > //  Output random decimals, such as: 0.5031703060958534  </script> 
    • Floor (): A number can be rounded down

       <script type= "Text/javascript" > document.write (Math.floor ( 0.60) + "<br/>") // 0  document.write (Math.floor (0.40) + "<br/>") // 0  document.write (Math.floor (5) + "<br/>") // 5  document.write (Math.floor (5.1) + "<br/>") // 5  document.write (Math.floor ( -5.1) + "<br/>") // -6  document.write (Math.floor ( -5.9)) // -6  </script> 
    • Ceil (): A number can be rounded up

       <script type= "Text/javascript" > 0.60) + "<br/>") // 1  document.write (Math.ceil (0.40) + "<br/>") // 1  document.write (Math.ceil (5) + "<br/>") // 5  document.write (Math.ceil (5.1) + "<br/>") // 6  document.write (Math.ceil ( -5.1) + "<br/>") // -5  document.write (Math.ceil ( -5.9)) //  -5  </script> 
    • Max (): Returns the number of two specified numbers with a larger value

      <script type= "Text/javascript" >document.write (Math.max (5,7) + "<br/>")//7 document.write (Math.max ( -3,5) + "<br/>")//5document.write (Math.max ( -3,-5) + "<br/>") // -3document.write (Math.max (7.25,7.30))//7.3</script>
    • MIN (): Returns a number with the lowest value in the specified number, with the effect similar to the Max demo

  • Array functions
    • Concat (): method is used to concatenate two or more arrays. The method does not alter the existing array, but simply returns a copy of the connected array

      <script type= "Text/javascript" >var a = [];d ocument.write (a.concat (4,5)); // 1,2,3,4,5</script>
    • Join (): method is used to put all the elements in the array into a string. The elements are delimited by the specified delimiter.

      <script type= "Text/javascript" >varnew Array (3) arr[0] = "1"arr[1] = "2"  arr[2] = "3"document.write (Arr.join ())//</script>
    • Pop (): method is used to delete and return the last element of the array

       <script type= "Text/javascript" >var  arr = new  Array (3) arr[ 0] = "1" Span style= "color: #000000;" >arr[ 1] = "2" arr[ 2] = "3" document.write ( ARR)  // 1,2,3  document.write (" <br/> ") document.write (Arr.pop ())  //  3  document.write ("<br/>" ) document.write (arr)  // 1,2  </ Script> 
    • Push (): You can add one or more elements to the end of the array and return the new length.

      <script type= "Text/javascript" >varnew Array (3) arr[0] = "1"arr[1] = "2"  arr[2] = "3"+ "<br/>")//document.write (Arr.push ("a") + "<br/>") // adocument.write (arr)//1,2,3,a</script>
vBrowser Object BOM

1.windows objects:

    • Location Address Object
    • History Object
    • Document Object
    • Event Events Object
    • Screen Object
    • Navigator Browser Object

2. Call Mode:

    • Windows. Properties = ""
    • Windows. Method ();

Three pop-up dialog methods for 3.windows objects:

    • Alert () To display a warning box with a specified message and an OK button Demo
    • Confirm () To display a dialog box with the specified message and OK and Cancel buttons Demo
    • Prompt () To display a dialog box that prompts the user for input, Demo

Methods for two pop-up boxes for 4.windows objects:

  • Open () Opens a new browser window or finds a named window

    Parameters Description
    Url An optional string that declares the URL of the document to display in a new window. If this argument is omitted, or if its value is an empty string, then the new window will not display any documents.
    Name An optional string that is a comma-delimited list of features, including numbers, letters, and underscores that declare the name of the new window. This name can be used as the value of the tag <a> and <form> property target. If the parameter specifies a window that already exists, the open () method no longer creates a new window, but simply returns a reference to the specified window. In this case, the features will be ignored.
    Features An optional string that declares the characteristics of the standard browser to be displayed for the new window. If this argument is omitted, the new window will have all the standard features. In this table of window features, we describe the format of the string in detail.
    Replace

    An optional Boolean value. Specifies whether the URL loaded into the window creates a new entry in the window's browsing history or replaces the current entry in the browsing history. The following values are supported:

    • True-url replaces the current entry in the browsing history.
    • False-url creates a new entry in the browsing history.
  • ShowModalDialog () Pop-up mode window, this usage comparison

5.windows object two ways to start the timer:

    • The SetInterval () method invokes a function or evaluates an expression according to the specified period (in milliseconds). The SetInterval () method keeps calling functions until Clearinterval () is called or the window is closed. The ID value returned by SetInterval () can be used as a parameter to the Clearinterval () method.
    • The SetTimeout () method is used to call a function or evaluate an expression after a specified number of milliseconds.

6.document three ways to find an object:

    • The getElementById () method returns a reference to the first object that owns the specified ID
    • The getElementsByTagName () method returns a collection of objects with the specified label name.
    • The Getelementsbyname () method can return a collection of objects with the specified name.

7. Common JS Events:

    • The OnClick event occurs when the object is clicked
    • onMouseOver Mouse over Event
    • The onmouseout event occurs when the mouse pointer moves out of the specified object.
    • The OnLoad event occurs immediately after the page or image has finished loading.
    • The onfocus event occurs when the object receives focus.
    • The onblur event occurs when the object loses focus.
    • The onfocus event occurs when the object receives focus.
    • The onfocus event occurs when the object receives focus.

8. Browser Object properties:

    • The AppName property returns the name of the browser.
    • The appCodeName property is a read-only string that declares the browser's code name.
    • The AppVersion property returns the browser's platform and version information. The property is a read-only string.
vDom

Dom mainly needs to be used in the actual combat, I just list some of the DOM's common properties

1.DOM Properties:

    • The ChildNodes property returns a collection of child nodes of the node to NodeList the object
    • DocumentElement root Node
    • Document.body body
    • Document.body.childNode get the child node collection of the BODY element
    • NodeName node Name
    • The Attributes property returns a collection of properties for the specified node, that is, NamedNodeMap
    • NodeType node type
    • NodeValue node Value

Basic JavaScript tutorial [warm know new one]

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.