JS for strings, time dates, operation of mathematical functions, and use of common events (organization event bubbling)

Source: Internet
Author: User
Tags mathematical functions time and date

One, the operation of the string

1. Turn Capital:

S.tolowercase ();

2. Turn Capital:

S.touppercase ();

3, the interception of the string:

S.SUBSTR (3,4); -Intercept from index 3 and intercept 4 bits. The index starts at 0.

4. Detach the string as specified:

S.split (","); Enclose the specified character in quotation marks. The return is an array.

5. String Length:

S.length;

6, the index of one character in the string:

S.indexof ("World"); World the first occurrence of the position in the string, the index is returned, if no 1 is returned.

7, o the last occurrence of the string in the position:

S.lastindexof ("O");

Ii. operation of Time and date

1. Current Time:

var d =new Date ();

2. Define a time:

var d =new Date(2017,03,02); February 2, 2017.

3. Year of Acquisition: D.getfullyear ();    Get month: D.getmonth (); 1 less months to take out.     Get Day: D.getdate (); Get Day of the Week: D.getday ();

Acquisition Hours: D.gethours ();              Get minutes: D.getminutes ();     Get seconds: d.getseconds (); Set year: D.setfullyear (); Add 1 when setting the month.

Third, the operation of mathematical functions:

1, Math.ceil (); Take the upper limit

2, Math.floor (); Lower limit

3, math.sqrt (); Open Square

4, Math.Round (); Rounded

5, Math.random (); Random number, between 0-1.

Iv. Events

OnClick Mouse Single Trigger

OnDblClick Mouse double-click Trigger

onmouseover Mouse Move-in trigger

onmouseout Mouse move out Trigger

OnMouseMove Mouse on top move trigger

onchange content Change Trigger

onblur Loss of Focus trigger (focus refers to the cursor position)

Onfocus Get intersection Trigger

OnKeyDown Press the button to trigger

onkeyup Lift button trigger can be displayed synchronously

All content of Window.onload browser is triggered after play, only one onload event is allowed on a page, not recommended

Window.onresize Browser size change is triggered

Gets the current client width, height:

Window.onresize=fuction () {

var wid =document.documentelement.clientwidth;

var hei =document.documentelement.clientheight;

}

Block event bubbling: window.event? window.event.cancelBubble = True:e.stoppropagation ();

JS for strings, time dates, operation of mathematical functions, and use of common events (organization event bubbling)

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.