"Therelationship between JQ and JS ": JQ is a common method for the encapsulation, simplification and optimization of JS.
" Little Tricks " Ctrl+k+d:vs write code when the format is messy, the shortcut keys used to organize the code
------------------------------------------------------------------------------------------------------
1. Get Time:
Method |
Describe |
getFullYear () |
Returns a four-digit year |
GetMonth () |
Return month (starting from 0, January =0,2 month =1, ... ) |
GetDate () |
Return date (starting from 1, this date) |
GetDay () |
Returns the day of the week (Sunday = 0, Monday = 1, ... ) |
GetHours () |
Returns the number of hours (starting at 0, the number of hours) |
Getminutes () |
Returns the number of minutes (starting at 0, the number of minutes) |
Getseconds () |
Returns the number of seconds (starting at 0, the number of seconds) |
Getmilliseconds () |
Returns the number of milliseconds (starting at 0, the number of milliseconds) |
GetTime () |
Returns the number of milliseconds elapsed from GMT January 1, 1970 0:0 0 seconds (86400000 milliseconds = 1 days) |
1) Wording:
function Myclick ()
{
var mydate=new Date ();
Alert (Mydate.getday ());
}
2) Get the number of days between set dates:
var startstr = "2014-4-14" ;; var Startarray = Startstr.split ("-" new Date (Startarray[0], startarray[1]-1, startarray[2]); var endDate = new Date (Endarray[0], endarray[1]-1, Endarray[2var diffdays = (enddate-startdate)/86400000;alert ( DiffDays); </script>
2. Value:
Maximum value: Math.max (18,12,22,33)
Minimum value: Math.min (18,2,2,3,1)
Round up: Math.ceil (25.9)//It rounds the number up to the nearest integer
Rounding Down: Math.floor (25.6)
Rounding: Math.Round (25.6)
Random number between 0~1: Math.random ()//excluding 0 and 1
Example
Returns an integer between 1~100 including 1 and 100:varinum=math.floor (Math.random () *100+1)
3 window
1) Open a window:window.open("http://www.baidu.com", "_blank", "height=300,width=400,top=30,left=140,resizable= Yes ");
Resizable Whether you can resize a new window by dragging the default is Yes
Scrollable whether the new window shows scroll bars default to No
2) Close the new window:window.close ()
3) Window.history.go (-1)//browser back one page
Window.history.go//forward one page
4. Timer Instance
1) Print AAAA after 5 seconds:
SetTimeout (function() { alert ("AAAA");},5000);
The *settimeout () method is used to call a function or evaluate an expression after a specified number of milliseconds.
Effect: 5 Seconds after the popup box shows AAAA, it does not loop repeatedly.
2) Print the number once every 2 seconds:
var i=0; SetInterval (function() { i++; document.write (i);},2000);
The *setinterval () method invokes a function or evaluates an expression according to the specified period (in milliseconds).
Effect: Every 2 seconds, print 1, 2, 3, 4, 5 ..., see the interface is: 123456789101112 ...
3) Print a number every 2 seconds, until 10:
var i=0; var timer=setinterval (function() { i++if (i==10) {clearinterval (timer);} document.write (i) ;},2000);
The *clearinterval () method cancels the timeout set by SetInterval ().
Effect: Only print until 10, interface: 12345678910
4) Every 1 seconds, print 1 to 10 and return to 1:
var i=0; var b=true;function () {if (b) {I++if (B==false; if (I==1if (I==10false;} document.write (i);},1000)
* Note: Stop timer can only use clearinterval () method to stop, with return and so on cannot stop the timer, the timer will persist until clearinterval () appears.
5) Generate 1-100 random integers, give 5 chance to see if you can guess the right:
var Inumber=math.floor (Math.random () *100+1);//Generate a random integer between 1-100 as the winning numberForvar i=1;i<7;i++){if (i==6{alert ("Five chance ran out, winning number is:" +Inumber);Return; }Else{var sinput=prompt ("Please enter an integer between 1-100");var ninput=Number (sInput);if (IsNaN (ninput)) {//Determine if the input is a number alert ("You're not typing a number.")); }Else{if (Ninput=parseint (ninput)) {// judge whether the input is an integer if (ninput>100| | Ninput<1else{if (Ninput> Inumber) {alert ("The content you entered is too large" if (Ninput<inumber) {alert ("The content you entered is too small" ); } else alert ("Congratulations on winning!") "); returnelse{alert ("You are not entering an integer" ); } } }}
Nineth Course Focus (JS statement: Get time, numeric value, timer)