Useful JS front-end code

Source: Internet
Author: User
Tags exit in mathematical functions

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 e xpression]; [condition]; [upadte e xpression]) {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 = "/blog/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 = terraform Doc ument. Forms [0]
For (VAR I = 0; I <form. elements. length; I ++ ){
If (Form. elements. type = "text "){
Form. elements. 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 = "/blog/AAA. js"> </SCRIPT>
50. Specify the HTML displayed in a browser that does not support scripts: <NoScript> </NoScript>
Examples: <a href = "/blog/a.html" onclick = "location. href ="/blog/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.cnblogs.com/css/";, "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.cnblogs.com/css ";);
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.
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 () to make all strings small.
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
Tag: Javascript

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.