Home > Article > Web Front-end > Collection of 107 basic knowledge in JavaScript Recommended_Basic knowledge
1.document.write(""); Output statement
2. The comment in JS is //
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 sum of the elements in the form Value: document.getElementById("ID number of the element in the form").name(or value)
6. A lowercase to uppercase js: document.getElementById("output").value = document.getElementById ("i
nput").value.toUpperCase();
7. Value types in JS: String, Number, Boolean, Null, Object, Function
8. Convert the character type in JS to numeric type: parseInt(), parseFloat()
9. Convert the number in JS to character type: ("" variable)
10.JS The string length in is: (length)
11. Characters in JS are connected with characters using numbers.
12. The comparison operators in JS are: == equal to, != is not equal to,>,>=,<.>
13. Use: var to declare variables in JS
14. Judgment statement structure in JS: if(condition ){}else{}
15. Loop structure in JS: for([initial expression];[condition];[upadte expression]) {inside loop}
16. Loop abort The command is: break
17. Function definition in JS: function functionName([parameter],...)
18. When multiple forms appear in the file, you can use document.forms[0], document.forms[1] instead.
//http://www.devdao.com
19. Window: open a window window.open(), close a window: window .close(), the window itself: self
20. Status bar settings: window.status="Character";
21. Pop-up prompt message: window.alert("Character") ;
22. Pop up the confirmation box: window.confirm();
23. Pop up the input prompt box: window.prompt();
24. Specify the currently displayed link Location: window.location.href="URL"
25. Get 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 to get elements: document.getElementById()
30. Set the values of all text-type members in the form to empty:
var form = window.document.forms[0]
for (var i = 0; i if (form.elements.type == "text"){
form.elements.value = "";
}
}
31. Determine whether the check button is checked in JS: document.forms[0].checkThis.checked (the checked attribute represents whether it is checked or not
returns TRUE or FALSE)
32. Radio button group (the names of the radio buttons must be the same): take the length of the radio button group document.forms[0].groupName.length
33. Determine whether the radio button group is Checked is also used for selection.
34. The value of the drop-down list box: document.forms[0].selectName.options[n].value (n sometimes uses the name of the drop-down list box plus .sel
ectedIndex to determine the selected value)
35. Definition of string: 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 means not found.
38. Get a character at the specified position in the string: StringA.charAt(9);
39. Get the sub-characters at the specified starting point and end point in the string String: stringA.substring(2,6);
40. Mathematical functions: Math.PI (returns pi), Math.SQRT2 (returns square root), Math.max (value1, value2) returns two The most
in the number, Math.pow(value1,10) returns the tenth power of value1, Math.round(value1) rounding function, Math.floor(Math.ra
ndom()*(n 1)) returns a random number
41. Define date type variables: var today = new Date();
42. List of date functions: dateObj.getTime() Get the time, dateObj.getYear() gets the year, dateObj.getFullYear() gets the
four-digit year, dateObj.getMonth() gets the month, dateObj.getDate() gets the day, dateObj.getDay() gets Date, dat
eObj.getHours() gets the hours, dateObj.getMinutes() gets the minutes, dateObj.getSeconds() gets the seconds, dateObj.setTi
me(value) sets the time, dateObj.setYear(val) sets the year, dateObj.setMonth(val) sets the month, dateObj.setDate(va
l) sets the day, dateObj.setDay(val) sets the day of the week, dateObj.setHours sets the hour, dateObj.setMinutes(val) sets minutes,
dateObj.setSeconds(val) sets seconds [Note: This date and time starts from 0]
43. FRAME representation: [window. ]frames[n].ObjFuncVarName,frames["frameName"].ObjFuncVarN
ame,frameName.ObjFuncVarName
44.parent represents the parent object, top represents the top object
45. The parent window that opens the child window is: opener
46. Indicates the current location: this
47. When calling a JS function in a hyperlink, use: (javascript:) Add the function name
48. This js will not be executed in old browsers:
49. Reference a file-style js:
50. Specify in HTML displayed by browsers that do not support scripts:
51. When there are both hyperlinks and onCLICK events, older browsers will redirect to a.html, otherwise they will redirect to b.html. Example: dfsadf
52.JS’s built-in objects include: Array, Boolean, Date, Error, EvalError, Function, Math, Number, Object, RangeError,
ReferenceError, RegExp, String, SyntaxError, TypeError, URIError
53. Line break in JS: n
54. Window full screen size:
55. all in JS represents all the elements below it
56 .Focus order in JS: document.getElementByid("Form Element").tabIndex = 1
57. The value of innerHTML is the value of the form element: such as
"how are you"
, then the value of innerHTML is: how are you
58. The value of innerTEXT is the same as above, but this kind of tag will not be displayed.
59.contentEditable can set whether the element can be modified, isContentEditable returns the status of whether it can be modified.
60.isDisabled determines whether it is a prohibited state. disabled sets the prohibited state
61.length gets the length , returns an integer value
62.addBehavior() is an external function file called by JS. Its extension is .htc
63.window.focus() makes the current window visible to all Before the window.
64.blur() means losing focus. The opposite of FOCUS().
65.select() means the element is selected.
66. Prevent The user enters text into the text box: onfocus="this.blur()"
67. Get the number of occurrences of this element on the page: document.all.tags("div (or other HTML tags) ").length
68. There are two types of form output in JS: modal and non-modal.window.showModaldialog(),window.showModeless()
69. Status bar Text setting: window.status='text', default status bar text setting: window.defaultStatus = 'text.';
70. Add to favorites: external.AddFavorite("http:// www.dannyg.com"t;,"jaskdlf");
71. No action is taken when a script error is encountered in JS: window.onerror = doNothing; The syntax for specifying an error handle is: window.on
error = handleError;
72. Specify the parent window of the currently opened window in JS: window.opener, which supports multiple continuations of opener.opener....
73 .Self in JS refers to the current window
74. Status bar display content in JS: window.status="content"
75. Top in JS refers to the frame set The top-level framework
76. Close the current window in JS: window.close();
77. Propose a confirmation box in JS: if(confirm("Are you sure? "))else{alert("Not Ok");}
78. Window redirection in JS: window.navigate("http://www.sina.com.cn"t;);
79. Printing in JS: window .print()
80.Prompt input box in JS: window.prompt("message","defaultReply");
81.Window scroll bar in JS: window.scroll (x,y)
82. Scroll the window to the position in JS: window.scrollby
83. Set the time interval in JS: setInterval("expr",msecDelay) or setInterval(funcRef ,msecDelay) or setTimeou
t
84. The modal display in JS is in IE4, but not in NN: showModalDialog("URL"[,arguments][,features]);
85. The handle used before exiting in JS: function verifyClose(){event.returnValue="we really like you and ho
pe you will stay longer.";}} window .onbeforeunload=verifyClose;
86. The file handle used when the form is called for the first time: onload()
87. The file handle called when the form is closed: onunload()
Attributes of 88.window.location: protocol(http:),hostname(example.com),port(80),host(e
xample.com:80),pathname( "/a/a.html"), hash ("#giantGizmo", refers to jumping to the corresponding anchor), href (all information
)
89.window. location.reload() refreshes the current page.
90.window.history.back() returns to the previous page, window.history.forward() returns to the next page, window.history.go(returns
What page, you can also use the visited URL)
91.document.write() output without line breaks, document.writeln() output with line breaks
92.document .body.noWrap=true; prevent link text from wrapping.
93. Variable name.charAt (number), take the character of the variable.
94." abc".charCodeAt (number), returns the ASCii code value of which character.
95. String concatenation: string.concat(string2), or use = to connect
96. Variable.indexOf("Character", starting position), returns the position of the first occurrence (calculated from 0)
97.string.lastIndexOf(searchString[,startIndex]) the last occurrence Position.
98.string.match(regExpression), determine whether the characters match.
99.string.replace(regExpression,replaceString) replace the existing string.
100.string.split (separator) returns an array storage value.
101.string.substr(start[,length]) takes the string from the number to the specified length.
102.string.toLowerCase() changes all characters to lowercase.
103.string.toUpperCase() changes all characters to uppercase.
104.parseInt(string[,radix (representing base)]) is forced to be converted to an integer type.
105.parseFloat(string[,radix]) is forced to be converted to a floating point type.
106.isNaN (variable): test Whether it is a numeric type.
107. Keywords for defining constants: const, keywords for defining variables: var