Over 100 useful JavaScript Functions and a large set of basic writing methods

Source: Internet
Author: User
1. Document. Write (""); For the output statement
2In. JS, the comment is//
3. The traditional HTML document sequence is: Document-> HTML-> (Head, body)
4The Dom sequence in a browser window is: window-> (navigator, screen, history, location, document)
5. Get the element name and value 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 ();
7Value types in. JS: String, number, Boolean, null, object, Function
8Convert the numeric type in. js to the numeric type: parseint (), parsefloat ()
9Convert numbers in. js to numeric :(""+ Variable)
10In. JS, the string length is (length)
11The character in. JS is connected with the character using the plus sign.
12The comparison operators in. js include: = equals ,! = Not equal to,>, >=, <. <=
13Declare variables in. js using: var for declaration
14Judgment statement structure in. JS:If(Condition ){}Else{}
15Loop Structure in. JS:For([Initial expression]; [condition]; [upadte expression]) {inside loop}
16The command for loop abort is:Break
17Function 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] To replace.
19. Window: open window. open (), close a window: window. Close (), the window itself: Self
20. Set the status bar: window. Status ="Character";
21Window. Alert ("Character");
22. Pop-up confirmation box: window. Confirm ();
23Window. 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 to obtain 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 <! --// -->
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 there are both superlinks and onclicktasks, the browser turns to a.html, And the browser turns to B .html if it is not. For example: <a href ="A.html"Onclick ="Location.href=' 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
53Line feed 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>
55All in. js represents all the elements in its lower layer.

56Focus sequence in. JS: Document. getelementbyid ("Form element"). Tabindex =1
57The value of. innerhtml is the value of the form element, for example, <p id ="Para">"How are <em> You </em>"<P> </P>, the value of innerhtml is: how are <em> You </em>
58The 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 status bar text: window. Status ='Text', Default status bar text settings: window. defaultstatus ='Text .';
70. Add to favorites: External. AddFavorite (Http://www.google.com","Google");
71When a script error occurs in. JS, do not perform any operation: window. onerror = donothing; the syntax for specifying the error handle is window. onerror = handleerror;
72Specify the parent window currently opened in. JS: window. opener, supporting multiple continuation of opener. opener.
73Self in. js refers to the current window
74. Js status bar display content: window. Status ="Content"
75In. JS, top refers to the top-level framework in the framework set.
76Close the current window in. JS: window. Close ();
77The confirmation box in. JS is as follows:If(Confirm ("Are you sure? ") {Alert ("OK");}Else{Alert ("Not OK");}
78Window redirection in. JS: window. navigate (Http://www.google.com");
79Print in. JS: window. Print ()
80Window. Prompt ("Message","Defaultreply");
81Window scroll bar in. JS: window. Scroll (x, y)
82In. JS, the window is rolled to the position: window. scrollby
83Set the time interval in. JS: setinterval ("Expr", Msecdelay), setinterval (funcref, msecdelay), or setTimeout
84The Mode in. JS is displayed in ie4 + lines, but not in NN: showmodaldialog ("Url"[, Arguments] [, features]);
85Handle 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. The 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 (returns the page number, or you can use the accessed URL)
91. Document. Write () does not wrap output, document. writeln () line feed output
92. Document. 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 position that appears (from0Start computing)
97. String. lastindexof (searchstring [, startindex]) position where the last error occurred.
98. String. Match (regexpression) to determine whether the characters match.
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 lowercase.
103. String. touppercase () converts all characters to uppercase.
104. Parseint (string [, Radix (in hexadecimal format)]) 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. Defines the keyword of a constant:Const, Defines the keyword of the variable: var </em>
Related Article

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.