Function object in JavaScript
JavaScript statements are often used in the process of website production. Mastering some related JavaScript structures is of great reuse in website production!
1.document.write(""); Output statement
2. The comment in JS is //
3. The traditional HTML document sequence is: document->html->(head,body)
4. DOM in a browser window The order is: window->(navigator, screen, history, location, document)
5. Get the name and value of the element in the form: document.getElementById("ID number of the element in the form").name (or value)
6. One JS that converts lowercase to uppercase: document.getElementById("output").value = document.getElementById("input").value.toUpperCase();
7. Value types in JS: String, Number, Boolean, Null, Object, Function
8. The character type in JS is converted into a numerical type: parseInt(), parseFloat()
9. The number in JS is converted into a character type: (""+variable)
10. The length of the string in JS is: (length )
11. The + sign is used to connect characters with characters in JS.
12. The comparison operators in JS are: == equal to, != not equal to, >, >=, <.<=
13. Use of variables in JS to declare :var to make a statement
14. Judgment statement structure in JS: if(condition){}else{}
15. Loop structure in JS: for([initial expression];[condition];[upadte expression]) {inside loop }
16. The command to terminate the loop is: break
17. Function definition in JS: function functionName([parameter],...){statement[s]}
18. When multiple forms appear in the file, you can use document .forms[0],document.forms[1] instead.
19. Window: open the 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 confirmation box: window.confirm();
23. Pop up input prompt box: window.prompt();
24. Specify the current Display the location of the link: 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 the element: document.getElementById()
30. Set the values of all text members in the form to empty:
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. Determine whether the check button is checked in JS: document.forms[0].checkThis.checked (the checked attribute represents whether it is selected and returns TRUE or FALSE)
32. Radio button group (the names of the radio buttons must be the same): Get the length of the radio button group document.forms[0].groupName.length
33. Checked is also used to determine whether the radio button group is selected.
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 .selectedIndex to determine the selected value)
35. Definition of string: var myString = new String("This is lightsword");
36. Convert string to uppercase :string.toUpperCase(); Convert the string to lowercase: string.toLowerCase();
37. Return the position where string 2 appears in string 1: String1.indexOf("String2")!=-1 means it is not found .
38. Get a character at the specified position in the string: StringA.charAt(9);
39. Get the substring at the specified starting point and end point in the string: stringA.substring(2,6);
40. Mathematical function: Math .PI (returns pi), Math.SQRT2 (returns the square root), Math.max(value1, value2) returns the highest 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 random numbers
41. Define date variables: var today = new Date();
42. Date function list: dateObj. getTime() gets 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 the date, dateObj.getHours() gets the hours, dateObj.getMinutes() gets the minutes, dateObj.getSeconds() gets the seconds, dateObj.setTime(value) sets the time, dateObj.setYear(val) sets the year, dateObj.setMonth(val) sets the month , dateObj.setDate(val) sets the day, dateObj.setDay(val) sets the day of the week, dateObj.setHours sets the hours, dateObj.setMinutes(val) sets the minutes, dateObj.setSeconds(val) sets the seconds [Note: This date and time starts from Starting from 0]
43. FRAME representation: [window.]frames[n].ObjFuncVarName,frames["frameName"].ObjFuncVarName,frameName.ObjFuncVarName
44.parent represents the parent object, top represents the top object
45.Open the child The parent window of the window is: opener
46. Indicates the current location: this
47. When calling a JS function in a hyperlink, use: (javascript:) to start with the function name
48. This is not executed in old browsers JS:<!-- //-->
49. Reference a file-style JS: <script type="text/javascript" src="aaa.js"></script>
50. Specify browsers that do not support scripts HTML displayed by the browser: <noscript></noscript>
51. When there are both hyperlinks and ONCLICK events, the old version of the browser will redirect to a.html, otherwise it will redirect to b.html. Example: <a href="a.html " onclick="location.href='b.html';return false">dfsadf</a>
52. The built-in objects of JS are: Array, Boolean, Date, Error, EvalError, Function, Math, Number, Object, RangeError, ReferenceError, RegExp, String, SyntaxError, TypeError, URIError
53. Line breaks in JS:n
54. Window full screen size: <script>function fullScreen(){ this.moveTo(0,0);this.outerWidth=screen .availWidth;this.outerHeight=screen.availHeight;}window.maximize=fullScreen;</script>
55.all in JS represents all 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 <p id="para">"how are <em>you</em>"</p>, then the value of innerHTML is: how are <em>you</em>
58. The value of innerTEXT is the same as above, except that the <em> tag will not be displayed.
59.contentEditable can set whether the element can be modified, and 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 and returns an integer value
62.addBehavior() is an external function file called by JS. Its extension is .htc
63.window.focus( ) puts the current window in front of all windows.
64.blur() means losing focus. The opposite of FOCUS().
65.select() means the element is selected.
66. Prevent the user from entering text in the text box: onfocus=" this.blur()"
67. Get the number of occurrences of this element in the page: document.all.tags("div (or other HTML tags)").length
68. There are two types of form output in JS: module 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","jaskdlf ");
71. Do not do anything when a script error is encountered in JS: window.onerror = doNothing; Specify the error handle The syntax is: window.onerror = handleError;
72. Specify the parent window of the currently opened window in JS: window.opener, supporting multiple continuations of opener.opener...
73. Self in JS refers to the current window
74 .The content displayed in the status bar in JS: window.status="content"
75.top in JS refers to the topmost frame in the frame set
76.Close the current window in JS: window.close();
77.Proposed in JS Confirm box: if(confirm("Are you sure?")){alert("ok");}else{alert("Not Ok");}
78. Window redirection in JS: window.navigate( " http://www.sina.com.cn ");
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. Window scroll to position in JS: window.scrollby
83. Set time interval in JS: setInterval("expr",msecDelay) or setInterval(funcRef, msecDelay) or setTimeout
84. The modal in JS is displayed on the IE4+ line, 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 hope you will stay longer.";}} window.onbeforeunload=verifyClose;
86. The file handle used when the form is called for the first time: onload()
87. When the window File handle called when the body is closed: onunload()
88. Attributes of window.location: protocol(http:), hostname( www.example.com), port(80), host(www.example.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.
89- 1.parent.location.reload() refreshes the parent object (for frames)
89-2.opener.location.reload() refreshes the parent window object (for single-open windows)
89-3.top.location.reload() Refresh the top object (for multiple windows)
90.window.history.back() returns to the previous page, window.history.forward() returns to the next page, window.history.go(returns to the first page, you can also Use the visited URL)
91.document.write() output without line wrapping, document.writeln() output with line wrapping
92.document.body.noWrap=true; prevent link text from wrapping.
93.Variable name.charAt(which number bit), get the character of the variable.
94. "abc".charCodeAt(number), return the ASCii code value of the 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 position of the last occurrence .
98.string.match(regExpression), determines whether the characters match.
99.string.replace(regExpression,replaceString) replaces the existing string.
100.string.split(separator) returns an array to store the value.
101.string. substr(start[,length]) takes the string from the digit to the specified length.
102.string.toLowerCase() makes all the strings lowercase.
103.string.toUpperCase() makes all the characters uppercase.
104 .parseInt(string[,radix(representing base)]) is forced to convert to integer type.
105.parseFloat(string[,radix]) is forced to be converted to floating point type.
106.isNaN(variable): Test whether it is numeric type.
107. The keyword for defining constants: const, the keyword for defining variables: var