JS System Object Math, Date, window

Source: Internet
Author: User
Tags custom name

Math object:

math.pi--represents the "constant" of pi.

Method:

  1. Math.max (value 1, value 2, ...)--the maximum value in a number of values is obtained.
  2. Math.min (value 1, value 2, ...)--The minimum value in a number of values is obtained.
  3. Math.Abs (value 1)--the absolute value of 1 is obtained
  4. Math.pow (x, y)-The Y-order of the value X, which is the "power operation"
  5. MATH.SQRT (x)--To obtain the root of X
  6. Math.Round (x)--The result value of rounding X is obtained;
  7. Math.floor (x)--the result of a downward rounding of X, that is, a maximum integer greater than x is found.
  8. Math.ceil (x)--the result of an upward rounding of X, that is, to find a smallest integer not less than X
  9. Math.random ()--Get a random "decimal" in the range of 0~1, with 0, but not 1
General practice for obtaining a random integer between two integers (n1,n2): var v1 = math.random () v1 = v1 * (n2-n1+1), V1 = Math.floor (v1) + n1;//at this time V1 is the result//the above 3 steps to write a step is (pass Formula): var v1 = Math.floor (Math.random () * (n2-n1+1)) + N1

  

Date object:

Declares a Date object

D1 = new Date (); Defines a Date object that represents the "current time".

D2 = new Date ("2013/9/25 11:18:19"); Use a string to define a date object for a specified time (moment)

D3 = new Date (2013, 9, 25, 11, 18, 19); Use multiple (at least 3) numbers to define a date object for a specified time

D4 = new Date (2324624252312); A number is used to define a date object of a specified time.

Common methods for TIME objects:

V1 = d1.tolocalestring (); Acquisition time is "local notation"

V1 = D1.gettime (); Get a "millimeter" of a time-starting from the time origin.

The following is a data value in the Get time:

V1 = D1.getfullyear (); Get the number of years--is a number, the same as

V1 = D1.getmonth (); Get the number of months-note: This number is calculated starting from 0, which can only be: 0-11

V1 = D1.getdate (); Number of dates acquired

V1 = D1.getday (); Get the number of weeks

V1 = d1.gethours (); Get the number of hours

V1 = D1.getminutes (); Get the number of minutes

V1 = D1.getseconds (); Gets the number of seconds

V1 = D1.getmilliseconds ();//Get the number of milliseconds

The following are some of the data values in the setup time:

D1.setfullyear (n); Set the number of years D1 this time object to n-that is, the year is modified, the same as the same.

D1.setmonth (n); Set the number of months

D1.             SetDate (n); Set the number of dates

D1.               Setday (n); Set the number of weeks

D1.           Sethours (n); Set Number of hours

D1.       Setminutes (n); Set the number of minutes

D1.       Setseconds (n); Set Number of seconds

D1. Setmilliseconds (n);//Set the number of milliseconds

Window object:

window Methods for several popup dialog boxes of the object:

    1. Window.alert ("Here is the text message"); Can be thought of as just a textual informational cue.
    2. var v1 = window.prompt ("text hint", "default Info")//Pop up a dialog box for the user to enter text information. Often used to ask the user a question that requires text to answer. It will return a "string value"
    3. var v2 = window.confirm ("A question of whether or not"); Pop up a question to the user asking "true and false", the user can answer "true and false". It is often used to ask the user a question that requires a yes/no response. It returns a Boolean value (True/false).

window.open ();--can pop up a "small" window, which will also be able to "place" a page.

The syntax form is as follows:

window.open ("To open Web address url", "Give me the name of a new Window", "New window appearance parameter set para");

URL: Can be a relative address or an absolute address.

Name: Custom name, follow the naming rules can be, such as N1, Win1, S1

Para: This setting has several items, each separated by commas, with each entry in the form of a key name = value. Examples are as follows:

width=400,

HEIGHT=300,

left=500,//indicates the distance from the left side of the screen

TOP=300,//indicates the distance from the top of the screen

menubar = yes; Indicates that the open window has a menu bar (no), or you can use the 1,0

toolbar = yes; Indicates that the open window has a toolbar (no), or you can use the 1,0

Location = yes; Indicates that the open window does not have an address bar (no), or you can use the 1,0 (the actual modern browser does not work for this, it becomes a location must be shown)

Scrollbars=yes;//indicates that the open window has a scroll bar.

............. Check out the "DHTML Complete Handbook"

General Examples:

window.open ("http://www.baidu.com", "db", "width=400, height=300, left=500,top=300, Menubar=yes, toolbar=1")

window4 A Small object location, history, screen, navigator

Location.href: Represents the current Web page address URL, which is a string.

This property can be either a value or a value-pay special attention to the fact that the assignment is "replace page"

In other words, this object allows us to implement "link function" on any label, like the meaning of a tag.

Method:

Location.assign ("A new web address URL"): In fact, the implementation of the link function, with the location.href assignment results.

Location.reload (); Re-refresh this page, similar to press F5

History object:

History.back ()--Let the browser window "step back" through the program.

History.forward ()--through the program to make the browser window "forward"

History.go (n): Let the current browser back or forward to a page. n can be a positive integer (representing a forward n step) or a negative integer (backward n steps)

Screen object:

Meaning: Represents the information of the display that the user is currently browsing the network--note that it is not a browser information.

Screen.width: Gets the width of the display resolution (in pixels)

Screen.height: Gets the height of the monitor resolution (in pixels)

Navigator object:

Meaning: On behalf of the user currently in use of the browser, actually used to get the browser information for programming use.

Property:

Navigator.appname: Get the app name of the browser

Navigator.appcodename: Get the "app id" of the browser

Navigator.appversion: Gets the version number of the browser

Navigator.useragent: Get "multiple messages" from the browser

In theory, the above properties are different for each browser, because they are unique information for each browser.

Timer method for Window object

Use of repetitive timers: The browser executes the code (function) repeatedly at a specified interval of time.

var T1 = Window.setinterval ("function ()", Interval time); Create a recurring timer and name it "T1"

Window.clearinterval (T1)//Clear (Stop/destroy) this repetitive timer

--the principle of alarm

Use of disposable timers: The browser executes the code (function) once after the specified time.

var t2 = window.settimeout ("function ()", Interval time); Create a one-time timer and name it "T2"

Window.cleartimeout (T2); Clear (Stop/destroy) the disposable timer

--Time bomb principle

        --disposable timers are typically used for some code that executes once

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.