JS Third Lecture

Source: Internet
Author: User
Tags natural logarithm rounds square root

* * document.getElementById ("docm"). InnerHTML = SSTR; Dynamically put the contents of sstr in the element with ID docm.

document.write (Anum.tostring ()); Converting the contents of a anum into a string output to a page overwrites the existing content.

First, the function

function calculates the program segment that loads the return value according to the entry parameters.

For example: function B (A, b) {has one or more parameters

var i = a + b; After calculation

return i; return result value

}

Ii. objects, attributes, methods

1, the definition of the class object:

A class is a reflection of an entity in the real world or the mind world in a computer that encapsulates data and the operations on that data. An object is a variable that has a class type. Classes and objects are the most basic concepts in object-oriented programming techniques.

* * Class and Object relationships:

A class is an abstraction of an object, and an object is a concrete instance of a class. Classes are abstract, do not occupy memory, and objects are specific and occupy storage space. A class is a blueprint for creating objects, which is a software template that defines methods and variables that are included in a particular type of object.

2. Properties:

It defines the characteristics of the object (such as size, color-to-screen position), or the behavior on the one hand (such as whether the object is active or visible). You can change the properties of an object by modifying its property values. For example, a user can control the appearance and position of an object by setting its properties. The properties of an object can only be set to a specific value at a time. For example, the current workbook cannot have two different names at the same time.

3. Method:

Refers to the actions that an object can perform. Every action you want to make is called a "method." For example, you use the Add method to add a new workbook or worksheet. Or add a new item to some form control.

* * Simply put: Everything in everyday life is an object. An object with the same attributes is called a class. The action that an object can perform is called a method.

Third, Date object

1, var mydate=new Date (); Declares a date-type variable and obtains the current DateTime.

2. Method (Date object has no attributes)

getFullYear () returns a four-digit year

GetMonth () returns the month (current month-1)

GetDate () return date (starting from 1)

GetDay () Return day of the week (Sunday 0)

GetHours () returns the number of hours (starting at 1)

Getminutes () returns the number of minutes (starting from 1)

Getseconds () returns the number of seconds (starting at 1)

Getmilliseconds () returns the number of milliseconds (starting at 0)

GetTime () returns the number of milliseconds elapsed from GMT time January 1, 1970 0:0 0 seconds

3, JS can not be the date of the direct operation of data, can only be segmented to get the data after the connection string way to obtain the final result date.

Iv. Math Object

1) Properties

Natural logarithm of Math.ln10 10

Natural logarithm of MATH.LN2 2

MATH.LOG2E logarithm of base e of 2

math.log10e logarithm of base e of 10

Math.PI Pi

Square root of Math.sqrt1_2 1/2

Square root of Math.sqrt2 2

2) method

Math.max (18,12,22,33) Take maximum value

Math.min (18,2,2,3,1) take the minimum value

Math.ceil (25.9) rounding up: rounds the number up to the nearest integer.

Math.floor (25.6) rounding down: rounds the number down to the nearest whole.

Math.Round (25.6) Rounding: Rounding down at less than 0.5, rounded up when it is greater than or equal to 0.5.

Random number between Math.random () 0~1:0 and 1 not included

such as: Var Inum=math.floor (Math.random () *100+1); Returns integers between 1~100, including 1 and 100

V. Window object

1) window.open ("http://www.baidu.com", "_blank", "height=300,width=400,top=30,left=140,resizable=yes");

This statement opens the search content in a new window.

Resizable whether the new window can be resized by dragging, by default Yes

Scrollable whether the new window shows scroll bars default to No

2) Close the new window

Window.close () Closes the current window.

3) alert (), confirm (), prompt ()

Alert ("hint"); gives the prompt window.

Confirm ("OK delete?")       "); A confirmation window with a yes/no button is given, returning a Boolean value.

Prompt ("hint"); Gives the user input Information window with the information of making the prompt.

4) Window.history.go (-1) browser back one page

Window.history.go forward one page

You can also use:

Window.history.back () browser back one page

Window.history.forward () forward one page

JS Third Lecture

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.