Summary of basic JavaScript knowledge and common methods, basic javascript knowledge
JAVASCRIPT is an indispensable part of AJAX technology. Therefore, it is most important to learn JAVASCRIPT well if you want to learn AJAX well and the popular AJAX framework.
I. Basic Knowledge:
1.doc ument. write (""); Output statement
2. Comments in JS are //
3. The traditional HTML document sequence is: document-> html-> (head, body)
4. the DOM sequence in a browser window is: window-> (navigator, screen, history, location, document)
5. Get the name and value of the element in the form: document. getElementById ("ID of the element in the form"). name (or value)
6. javascript: document. getElementById ("output"). value = document. getElementById ("input"). value. toUpperCase ();
7. value types in JS: String, Number, Boolean, Null, Object, Function
8. Convert the numeric type in JS to the numeric type: parseInt (), parseFloat ()
9. convert numbers in JS to numeric: ("" + variable)
The string length in 10. JS is: (length)
11. The character and character in JS are connected with the + number.
12. The comparison operators in JS include: = equals ,! = Not equal to,>, >=, <. <=
13. Declare variables in. JS using: var for declaration
14. JS judgment statement structure: if (condition) {} else {}
15. loop Structure in JS: for ([initial expression]; [condition]; [upadte expression]) {inside loop}
16. The command for loop abort is break.
17. function Definition in JS: function functionName ([parameter],...) {statement [s]}
18. When multiple form forms appear in the file, you can use document. forms [0], document. forms [1] instead.
19. window: open window. open (), close a window: window. close (), the window itself: self
20. Set the status bar: window. status = "character ";
21. window. alert ("character ");
22. Pop-up confirmation box: window. confirm ();
23. window. prompt ();
24. Specify the position of the currently displayed link: window. location. href = "URL"
25. Retrieve the number of all forms in the form: document. forms. length
26. close the output stream of the document: document. close ();
27. String append connector: + =
28. Create a document element: document. createElement (), document. createTextNode ()
29. method for getting the element: document. getElementById ()
30. Set the value of all text members in the form to NULL:
var form = window.document.forms[0]for (var i = 0; i<form.elements.length;i++){if (form.elements[i].type == "text"){form.elements[i].value = "";}}
31. Check whether the check button is selected in JS: document. forms [0]. checkThis. checked (the checked attribute indicates whether to select and return TRUE or FALSE)
32. Single-choice button group (the names of Single-choice buttons must be the same): Take the length of Single-choice button Group document. forms [0]. groupName. length
33. The single-choice button group also uses checked to determine whether it is selected.
34. value of the drop-down list box: document. forms [0]. selectName. options [n]. value (n sometimes adds. selectedIndex to the name of the drop-down list box to determine the selected value)
35. String definition: var myString = new String ("This is lightsword ");
36. Convert string to uppercase: string. toUpperCase (); Convert string to lowercase: string. toLowerCase ();
37. Return the position where string 2 appears in string 1: String1.indexOf ("String2 ")! =-1 indicates no.
38. Take a character at the specified position in the string: StringA. charAt (9 );
39. Retrieve the substring of the specified start point and end point in the string: stringA. substring );
40. mathematical functions: Math. PI (returns the circumference rate), Math. SQRT2 (return to the initiator), Math. max (value1, value2) returns the most value of the two numbers, Math. pow (value1, 10) returns the tenth power of value1, Math. round (value1) Rounding function, Math. floor (Math. random () * (n + 1) returns a random number.
41. Define a Date variable: var today = new Date ();
42. date function list: dateObj. getTime () Get the time, dateObj. getYear () returns the year, dateObj. getFullYear () returns the four-digit year, dateObj. getMonth () returns the month, dateObj. get date (), dateObj. getDay () returns the date (dateObj. getHours () returns the hour, dateObj. getMinutes (), dateObj. getSeconds () returns the second, dateObj. setTime (value) sets the time, dateObj. setYear (val): Year, dateObj. setMonth (val) sets month, dateObj. setDate (val) sets the date, dateObj. setDay (val) specifies the day of the week, dateObj. setHours: Set the hour, dateObj. setMinutes (val) set the score, dateObj. setSeconds (val) sets the second. [Note: this date and time start from 0]
43. FRAME representation: [window.] frames [n]. ObjFuncVarName, frames ["frameName"]. ObjFuncVarName, frameName. ObjFuncVarName
44. parent indicates the parent object, and top indicates the top object.
45. Open the parent window of the Child Window: opener
46. indicates the current location: this
47. when calling the JS function in the hyperlink, use: (javascript :) to start with and add the function name
48. Do not execute this JS in the old browser: <! -- // -->
49. Reference a file-type JS: <script type = "text/javascript" src = "aaa. js"> </script>
50. Specify the HTML displayed in a browser that does not support scripts: <noscript> </noscript>
51.when both hyperchains and onclickjs are available, the browser turns to a.html and the browser turns to B .html. For example: <a href = "a.html" onclick = "location.hrefw.' B .html '; return false"> dfsadf </a>
52. JS built-in objects include: Array, Boolean, Date, Error, EvalError, Function, Math, Number, Object, RangeError, ReferenceError, RegExp, String, SyntaxError, TypeError, URIError
Line feed in 53. JS:/n
54. full Screen Window Size: <script> function fullScreen () {this. moveTo (0, 0); this. outerWidth = screen. availWidth; this. outerHeight = screen. availHeight;} window. maximize = fullScreen; </script>
All in 55. JS represents all the elements in its lower layer.
56. JS focus sequence: document. getElementByid ("form element"). tabIndex = 1
57. the value of innerHTML is the value of the form element, for example, <p id = "para"> "how are <em> you </em>" </p>, the value of innerHTML is: how are <em> you </em>
58. The value of innerTEXT is the same as the above, but the <em> mark is not displayed.
59. contentEditable: You can set whether the element can be modified. isContentEditable returns whether the element can be modified.
60. isDisabled determines whether it is in the forbidden state. disabled sets the forbidden state.
61. length gets the length and returns an integer value.
62. addBehavior () is an external function file called by JS. Its extension is. htc.
63. window. focus () before all windows.
64. blur () indicates losing FOCUS. Opposite to FOCUS.
65. select () indicates that the element is selected.
66. Prevent users from entering text in the text box: onfocus = "this. blur ()"
67. Retrieve the number of elements that appear on the page: document. all. tags ("div (or other HTML tags)"). length
68. JS is divided into two forms of output: modal and non-modal. window. showModaldialog (), window. showModeless ()
69. Set the text in the status bar: window. status = 'text'. The default text in the status bar is window. defaultStatus = 'text .';
70. Add to favorites: external. AddFavorite ("http://www.dannyg.com", "jaskdlf ");
71. JS does not perform any operation when it encounters a script error: window. onerror = doNothing; syntax for specifying the error handle: window. onerror = handleError;
72. JS specifies the parent window of the window currently opened: window. opener. Multiple continuation of opener. opener... is supported.
73. self in. JS refers to the current window.
74. JS status bar display content: window. status = "content"
75. top in JS refers to the top-level framework in the framework set.
76. close the current window in JS: window. close ();
If (confirm ("Are you sure? ") {Alert (" OK ");} else {alert (" Not OK ");}
Window redirection in 78. JS: window. navigate ("http://www.sina.com.cn ");
79. JS print: window. print ()
Window. prompt ("message", "defaultReply ");
Window scroll bar in 81. JS: window. scroll (x, y)
82. JS: window. scrollby
Set the interval in 83. JS: setInterval ("expr", msecDelay), setInterval (funcRef, msecDelay), or setTimeout
The Mode in 84. JS is displayed in IE4 + lines, but not in NN: showModalDialog ("URL" [, arguments] [, features]);
85. handle used before exit in JS: function verifyClose () {event. returnValue = "we really like you and hope you will stay longer. ";}} window. onbeforeunload = verifyClose;
86. file handle used when the form is called for the first time: onload ()
87. file handle called when the form is closed: onunload ()
88. window. location attributes: protocol (http :), hostname (www.example.com), port (80), host (www.example.com: 80), pathname ("/a/a.html "), hash ("# giantGizmo", refers to jump to the corresponding anchor), href (all information)
89. window. location. reload () refresh the current page.
89-1.parent.location.reload () refresh the parent object (for frame)
89-2.opener.location.reload () refresh the parent window object (used for single-open window)
89-3.top.location.reload () refresh the top object (used to open multiple Windows)
90. window. history. back () returns the previous page, window. history. forward () returns the next page, window. history. go (return the page number, or use the accessed URL)
91.doc ument. write () output without line feed, document. writeln () line feed output
92.doc ument. body. noWrap = true; prevents link text from being broken.
93. variable name. charAt (nth digit), which is the nth character of the variable.
94. "abc". charCodeAt (NTH), returns the ASCii value of the nth character.
95. string connection: string. concat (string2), or use ++ = to connect
96. Variable. indexOf ("character", starting position), returns the first occurrence location (starts from 0)
97. string. lastIndexOf (searchString [, startIndex.
98. string. match (regExpression) to determine whether the character matches.
99. string. replace (regExpression, replaceString) to replace the existing string.
100. string. split (separator) returns an array storage value.
101. string. substr (start [, length]) takes the string from the nth digit to the specified length.
102. string. toLowerCase () converts all strings to lowercase.
103. string. toUpperCase () converts all characters to uppercase.
104. parseInt (string [, radix (representing hexadecimal)]) is forcibly converted to an integer.
105. parseFloat (string [, radix]) is forcibly converted to floating point type.
106. isNaN (variable): test whether it is Numeric.
107. Key words defining constants: const; key words defining variables: var
Ii. Common javascript methods:
1. index and indexof, lastindexof
Var arr = [1, 2, 3, 4, 5, 4, 3, 2, 1]; // when one parameter is set, the value is transmitted, and the Return index position (index starts from scratch) var index = arr. indexOf (4); // when there are two parameters, the first parameter indicates the starting position, the second parameter, or the value var index = arr. indexOf (4, 4); // alert (index) // 5
2. Five new superposition Methods
// Every: run a function on each element of the array. If true is returned, true is returned. If one element does not meet the conditions, falsevar result = arr is returned. every (function (item, index, array) {return item> 2 ;}); alert (result); // filter: execute a function for each element of the array to run the given function and return the filtered result var result = arr. filter (function (item, index, array) {return item> 2 ;}); alert (result); // forEach: the value of each item in the loop array, and execute a method arr. forEach (function (item, index, array) {alert (item );}); // map can run a function on each element of the array. After the function is executed, the new result is returned var result = arr. map (function (item, index, array) {return item * 2 ;}); alert (result) // some: Wake up the running of a function for each element of the array, if one item returns true, true is returned. If one returns false, falsevar result = arr is returned. some (function (item, index, array) {return item >=5 ;}); alert (result); // reduce reduceRight // previous value, current value, index location, arrayvar result = arr. reduce (function (prev, cur, index, array) {return prev + cur;}); alert (result); // 25var result = arr. reduceRight (function (prev, cur, index, array) {return prev + cur;}); alert (result) // 25
Articles you may be interested in:
- Learn common ExtJS (2) Button Methods
- Common Methods for learning ExtJS TextField
- Common ExtJS Panel learning methods
- Common ExtJS Window learning methods
- Common Methods for Javascript select drop-down box operations
- Two common methods for Js pop-up box port and Return Value
- Differences between jquery and javascript (comparison of common methods)
- Common Methods for js page Jump
- Common Methods for JS string Truncation
- Summary of three common methods of js array deduplication
- Common Methods of NODE. JS encryption module CRYPTO
- Introduction to two common methods for function calling in js
- Common Methods for js Implementation of buttons and background images