- Variables and variable scopes
variable and function declaration promotion definitions
Var a=100;
Function Test () {
As the variable declaration is lifted, a variable is declared with a value of undefined
Console.log (a);
Var a=10;
}
Data type detection method: typeof ()
function usage
indexOf Getting index values
charAt to get a single character based on the index value
concat Connection string
subStr getting a partial string
substring getting a partial string
Slice getting a partial string
Split (",") splits
Join Merge
String Case Conversion
tolowercase (small)
touppercase (Large)
shift Unshift from the beginning of the array to add or remove
pop push is added or removed from the end of the array
concat: Returns a new array that consists of adding parameters to the original array
Sort the sort from small to large reverse from large to smaller
Slice (start,end) array interception
Join ("|") Arrays are stitched into strings 1|2|3|4|5
Splice (start,deletecount,val1,val2,...) :
Delete the DeleteCount entry starting from the start position and insert the val1,val2 from that position,..
Console.log (' Get Date ')
Date = new Date ();
Console.log (date.getfullyear ())//Get the full year
Console.log (date.getyear ())//Get current year
Console.log (date.getmonth ())//Get the current month
Console.log (date.getdate ()); Get the date
Console.log (date.getday ()); Get the day of the week
Console.log (' Get Time ')
Date = new Date ();
Console.log (date.gethours ())//Get Hours
Console.log(Date.getminutes ()); Get points
Console.log (date.getseconds ()); Get seconds
Console.log (date.getmilliseconds ()); Get milliseconds
Console.log (date.gettime ()); Gets the millisecond value relative to 1970-01-01
Set the time
Date = new Date ();
Date.setfullyear (9999); = 9999
Date.setmonth (11); = 11: Month; actual December (month starting from 0)
Date.setdate (25); + 25: Day
Date.sethours (15); = 15: When
Date.setminutes (30); + 30: Points
Date.setseconds (40); = 40: Seconds
Date.setmilliseconds (333); = 333: milliseconds
Console.log (date); = December 25, 9999 15:30 40 sec 333 ms
- Looping statements
- Mathematical objects
Math
round (x) rounds the number to the nearest integer.
Random () returns an arbitrary number between 0 and 1.
Click events
Onclick
Click
<! DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<button id="btn1">aa</button>
<button id="btn2">bb</button>
<button id="btn3" onclick="change ()" >cc</ Button>
<button id="Btn4">ee</button>
<button id="btn5" onclick="change ()" >ff</button>
</body>
<script src="Http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js" ></script>
<script>
Click event OnClick is an event, and click is the method
$ (function () {
///The first method AddEventListener the added event RemoveEventListener () method to remove
var btn1=document. getElementById (' btn1 ');
var btn2=document. getElementById (' btn2 ');
Btn1.addeventlistener (' click ', change);
Btn2.addeventlistener (' click ',function() {alert (this). ID)},false);
The second method of
The click itself is the method that triggers the OnClick event, and the onclick event is triggered whenever the click () method of the element is executed.
$ ("#btn4"). Click (function() {
$ ("#btn3"). Click ();
}) ;
the function code in the//click method executes after the OnClick event executes, at which point the click Method acts as an append event
$ ("#btn5"). Click (function() {
Alert ("click btn5");
});
document.getElementById ("Btn3"). OnClick ();
document.getElementById ("Btn3"). Click ();
});
function change () {
alert ("onclick btn3");
}
</script>
</html>
Move the mouse over the left event
Onmouseenter Mouse Move Up
OnMouseLeave Mouse away
Dbclick event : Triggered by a rapid, continuous two-click
MouseDown Event : Triggered when the mouse is pressed
MouseUp Event : Triggered when the mouse is released
Toggle Events : mouse click to toggle Events
Hover event mouse pointer hover
mouseover Event : Triggered when the mouse moves from one element to another
mouseout Event : Triggered when the mouse moves out of an element
Focus Event
Focus () Get Focus
Blur () Lose Focus
<type="text"><span> Please enter your phone number? </span>
$ ("input"). Focus (function() {
$ ("span"). CSS ("display","inline"). FadeOut (2000);
});
Lose focus
$ ("input"). blur (function() {
Alert (" the input box has lost focus");
});
Common topics
1. The difference between placing a variable outside and putting it in a function:
Placing a variable outside is generally referred to as a global variable: active in the current page
Placing a variable in a function is generally referred to as a local variable: valid only within a function
2. The difference between "= =" and "= = ="
= = equals: As long as the values are equal, the data types are not necessarily equal (type conversions are done automatically)
1== ' 1 ' (equal)
= = = = All equals: The value must be equal to the data type when the comparison is equal
1=== ' 1 ' (unequal)
3. Functions
Knowing that a function is actually a tool, we only need to learn to use the tool to implement a function
This is the encapsulation of
4. The difference between split () join ()
The former is the form of an array of cuts, the latter is the conversion of arrays into strings
5. Topics
5.1 Write a function to return each character of string with a space, for example:
Addspace ("Hello World")//' H e l l o w o r l d '
5.2 Known to have the string "Get-element-by-id", write a function to turn it into a hump notation getElementById
5.3 Write a function that implements the following functions:
String inversion, such as ' 12345678 ' into ' 87654321 '
JS Basic Finishing Summary