2017-4-3 JS function Time Supplement

Source: Internet
Author: User
Tags mathematical functions

(a) function

1. String functions:

S.tolowercase ()---Convert to lowercase s.uppercase---converted to uppercase

S.SUBSTR (3,6)---from the start of the subscript is 4 intercept, intercept 6 characters, if not write the following number, directly intercepted to the last (string interception mainly with this)

S.substring (3,6)---from the position of the string third intercept to fifth (contains 3, 5, not subscript, is the position)

S.split ("); ---the string to be separated by the specified character, such as a comma in the middle, will not be all separated by commas

var s = ' a,b,c,d '; var d = s.spilt (', ') d becomes an array containing the characters a,b,c,d

S.length---The length of a string

S.indexof (' AAA '); ---the position of the first occurrence of the AAA in the string, if there is no return-1;

S.lastindexof (' a '); ---a where the last occurrence in the string

2. Time-Date function:

var a = new date ()---current time

var d = new Date (1999,3,2); --- define a time that is displayed on the April 2, 1999 note Time month plus 1  

D.getfullyear ();  ---year d.getmonth (); ---Take the month, take out the less 1 d.getdate (); --Take the day

D.getday ()---take weeks d.gethouse (); ---Take the hour d.getminutes (); ---take minutes

D.getseconds (); ---seconds.

D.getfullyear (); ---Set the year, the year is set to pay attention to add 1;

3. Mathematical functions:

Math.ceil ();  ---Go to the upper limit Math.floor (); ---lower limit

Math.sqrt ();  ---open square math.round (); ---rounding

Math.Round (); ---random number 0-1; contains 0, does not contain 1;

4. Trivia

Outside double quotes, inside to single quote, or add escape character

The value taken out of the text box is a string that needs to be converted to a number using parseint ().

S.match (reg); s represents a String, Reg represents a string, 2 matches, if 2 strings do not match, returns null

Equivalent to S==reg, if the double equals 12== ' 12 ' is equal, the reason is that the implicit conversion = = = is constant equals 12=== ' 12 ' returns is null

(ii) events

1.onclick Mouse Click event

2.ondbclick Mouse Double-click event

3.onmouseover Mouse Move-in events

4.onmouseout Mouse Out Event

5.onmouseove Mouse on top move is triggered

6.onchange as long as the content changes trigger onblur loses focus is triggered by the same 2 effects

7.onfocus get focus is trigger

8.onkeydown Press the button when the trigger

9.onkeyup when the button is lifted up to trigger

Add

1.window.onload () {}---All run out, in executing JS code

2.var wid = document.documentElement.clientWidth;---Gets the width of the client

can also get the height of the client, distance up, left distance

3.window.onresize = function () {}---size change, trigger time, can be used to record the height and width of the client (window, not all pages) changing size

Case: As the size of the window changes, the size of each change is recorded (size is the blank part of the page)

  

  

<!DOCTYPE HTML><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"/>    <title></title></Head><Body>    <spanID= "Id1"></span></Body></HTML><Scripttype= "Text/javascript">    vara=document.getElementById ('ID1'); Window.onresize= function () {              varwid=Document.documentElement.clientWidth; varHei=Document.documentElement.clientHeight; A.innertext= "Height"+wid+"width"+Hei; }</Script>

(iii) Supplementary

1. Block Event bubbling

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

The big Div set Small div is, if all write on the mouse to move the event, and get their ID, this time if not write block event bubbling, in the small Div is, will first get the small div ID, in obtaining the large div ID, this time need to write block bubbling event.

  

<!DOCTYPE HTML><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"/>    <title></title></Head><Body>        <Divstyle= "Height:400px;width:400px;background-color:yellow"ID= "Div1">        <Divstyle= "Height:100px;width:100px;background-color:blue"ID= "Div2">        </Div>    </Div></Body></HTML><Scripttype= "Text/javascript">    vara=document.getElementById ('Div1'); varb=document.getElementById ('Div2'); A.onmouseover= function() {alert (A.getattribute ('ID')); } b.onmouseover= function() {alert (B.getattribute ('ID')); Window.event?window.event.cancelBubble= true: E.stoppropagation (); }   </Script>

  

2017-4-3 JS function Time Supplement

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.