JavaScript functions can be divided into five categories:
・ Regular functions
・Array functions
・Date function
・Mathematical functions
・String function
1. Regular functions
JavaScript regular functions include the following 9 functions:
(1) alert function: displays a warning dialog box, including an OK button.
(2) confirm function: display a confirmation dialog box, including OK and Cancel buttons.
(3) Escape function: convert characters into Unicode code.
(4) eval function: calculates the result of the expression.
(5) isNaN function: Test yes (true) No (false) is not a number.
(6) parseFloat function: converts a string into a dot-number form.
(7) parseInt function: converts a string into integer number form (multiple-digital can be specified).
(8)prompt function: Display an input dialog box, prompting you to wait for user input. For example:
<script language="javascript"><!--alert("Input error");prompt("Please enter your name","Name");//(Title, preset value)confirm("Confirm no!");//--></script>(9) unescape function: decode characters encoded by the escape function.
2. Array function
The javascript array function includes the following 4 functions:
(1) Join function: convert and join all elements in the array into a string. example:
function JoinDemo(){ var a, b; a = new Array(0,1,2,3,4); b = a.join("-");//The separator return(b);//The returned b=="0-1-2-3-4"}(2) langth function: Returns the length of the array. example:
function LengthDemo(){ var a, l; a = new Array(0,1,2,3,4); l = a.length; return(l);//l==5}(3) reverse function: reverse the order of array elements. example:
function ReverseDemo() {var a, l;a = new Array(0,1,2,3,4);l = a.reverse();return(l); }(4) sort function: reorder array elements. example:
function SortDemo(){ var a, l; a = new Array("X" ,"y" ,"d", "Z", "v","m","r"); l = a.sort(); return(l);}3. Date function
The javascript date function includes the following 20 functions:
(1) getDate function: Returns the "day" part of the date, with values ranging from 1 to 31. example:
function DateDemo() {var d, s = "Today's date is: ";d = new Date();s += (d.getMonth() + 1) + "/";s += d.getDate() + "/";s += d.getYear();return(s); }(2) getDay function: Returns the day of the week, the value is 0~6, where 0 represents Sunday, 1 represents Monday,..., 6 represents Saturday. example:
function DateDemo() {var d, day, x, s = "Today is: ";var x = new Array("Sunday", "Monday", "Tuesday");var x = x.concat("Wednesday","Thursday", "Friday");var x = x.concat("Saturday");d = new Date();day = d.getDay();return(s += x[day]); }(3) getHours function: Returns the "hour" part of the date, with values ranging from 0 to 23. example.
function TimeDemo() {var d, s = "The current local time is: ";var c = ":";d = new Date();s += d.getHours() + c;s += d.getMinutes() + c;s += d.getSeconds() + c;s += d.getMilliseconds();return(s); }(4) getMinutes function: Returns the "minute" part of the date, with values ranging from 0 to 59. See the above example.
(5) getMonth function: Returns the "month" part of the date, with values ranging from 0 to 11. Where 0 means January, 2 means March,..., 11 means December. See the previous example.
(6) getSeconds function: Returns the "second" part of the date, with values ranging from 0 to 59. See the previous example.
(7) getTime function: Returns the system time.
function GetTimeTest() {var d, s, t;var MinMilli = 1000 * 60;var HrMilli = MinMilli * 60;var DyMilli = HrMilli * 24;d = new Date();t = d.getTime();s = "It's been "s += Math.round(t / DyMilli) + " days since 1/1/70";return(s); }(8) getTimezoneOffset function: Returns the time difference in this area (the region time difference between local time and GMT Greenwich Standard Time), in minutes.
function TZDemo() {var d, tz, s = "The current local time is ";d = new Date();tz = d.getTimezoneOffset();if (tz < 0)s += tz / 60 + " hours before GMT";else if (tz == 0)s += "GMT";elses += tz / 60 + " hours after GMT";return(s); }(9) getYear function: Returns the "year" part of the date. The return value is based on 1900, for example, 1999 is 99. There are examples before.
(10)parse function: Returns the number of milliseconds (local time) from 0:00 on January 1, 1970.
function GetTimeTest(testdate) {var d, s, t;var MinMilli = 1000 * 60;var HrMilli = MinMilli * 60;var DyMilli = HrMilli * 24;d = new Date();t = Date.parse(testdate);s = "There are "s += Math.round(Math.abs(t / DyMilli)) + " days "s += "between " + testdate + " and 1/1/70";return(s); }(11) setDate function: Set the "date" part of the date, the value is 0~31.
(12) setHours function: set the "hour" part of the date, the value is 0~23.
(13) setMinutes function: Set the "minute" part of the date, the value is 0~59.
(14) setMonth function: Set the "month" part of the date, the value is 0~11. Where 0 means January,..., 11 means December.
(15) setSeconds function: Set the "second" part of the date, the value is 0~59.
(16) setTime function: set time. The time value is the number of milliseconds calculated from 0:00 on January 1, 1970.
(17)setYear function: set the "year" part of the date.
(18) toGMTString function: convert the date into a string, which is GMT Greenwich Standard Time.
(19) setLocaleString function: convert the date into a string, which is local time.
(20) UTC function: Returns the number of milliseconds calculated from 0:00 on January 1, 1970, calculated in GMT Greenwich Standard Time.
4. Mathematical functions
JavaScript mathematical functions are actually Math objects, which include two parts: attributes and functions (or methods). Among them, the attributes mainly include the following contents.
Math.e:e (natural logarithm), Math.LN2 (natural logarithm of 2), Math.LN10 (natural logarithm of 10), Math.LOG2E (logarithm of e, base 2), Math.LOG10E (logarithm of e, base 10), Math.PI (π), Math.SQRT1_2 (square root value of 1/2), Math.SQRT2 (square root value of 2).
There are 18 functions:
(1)abs function: that is, Math.abs (same as follows), returns the absolute value of a number.
(2) acos function: Returns the inverse cosine value of a number, and the result is 0~π radians.
(3) asin function: Returns the inverse sine value of a number, and the result is -π/2~π/2 radians.
(4)atan function: Returns the arctangent value of a number, and the result is -π/2~π/2 radians.
(5)atan2 function: Returns the polar coordinate angle value of a coordinate.
(6) ceil function: Returns the minimum integer value of a number (greater than or equal to).
(7) cos function: Returns the cosine value of a number, and the result is -1~1.
(8) exp function: Returns the multiplier value of e (natural logarithm).
(9) floor function: Returns the maximum integer value of a number (less than or equal to).
(10)log function: natural logarithmic function, returns the natural logarithmic (e) value of a number.
(11)max function: Returns the maximum value of two numbers.
(12)min function: Returns the minimum value of two numbers.
(13)pow function: Returns the multiplier value of a number.
(14)random function: Returns a random value of 0 to 1.
(15) round function: Returns the rounded value of a number, the type is an integer.
(16)sin function: Returns the sine value of a number, and the result is -1~1.
(17) sqrt function: Returns the square root value of a number.
(18)tan function: Returns the tangent value of a number.
5. String function
The javascript string function completes the civilized work of string font size, color, length and search, including the following 20 functions:
(1) anchor function: generate a link point (anchor) for hyperlink use. The anchor function sets the name of the link point of <A NAME...>, and the other function link sets the URL address of <A HREF=...>.
(2) big function: add the font to number 1, the result is the same as the <BIG>...</BIG> tag.
(3) blink function: make the string flash, the result is the same as the <BLINK>...</BLINK> tag.
(4)bold function: make the font bold, the same result as the <B>...</B> tag.
(5) charAt function: Returns a character specified in the string.
(6) fixed function: Set the font to a fixed-width font, the same result as the <TT>...</TT> tag.
(7)fontcolor function: Set the font color, the result is the same as the <FONT COLOR=color> tag.
(8)fontsize function: Set the font size, the result is the same as the <FONT SIZE=n> tag.
(9) indexOf function: Returns the first index found in the string and starts looking for it from the left.
(10)italics function: Make the font italics, the same result as the <I>...</I> tag.
(11) lastIndexOf function: Returns the first index found in the string and starts looking for it from the right.
(12) length function: Returns the length of the string. (No need to include brackets)
(13)link function: generate a hyperlink, which is equivalent to setting the URL address of <A HREF=...>.
(14) Small function: reduce the font by one, the same result as the <SMALL>...</SMALL> tag.
(15)strike function: add a horizontal line in the middle of the text, the result is the same as the <STRIKE>...</STRIKE> tag.
(16) sub function: display string as subscript.
(17)substring function: Returns several characters specified in the string.
(18)sup function: display string as superscript.
(19) toLowerCase function: converts a string to lowercase.
(20) toUpperCase function: converts a string to uppercase.
The above article has a deep understanding of JavaScript built-in functions. It is all the content I have shared with you. I hope you can give you a reference and I hope you can support Wulin.com more.