107 common Javascript statements

Source: Internet
Author: User
Tags mathematical functions
Common Javascript test statements are also basic for front-end Javascript developers. 1. document. 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 characters in JS are connected to the characters and use delimiter.
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. window. status = "character ";
21. window. alert ("character ");
22. The confirmation box is displayed: 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 = terraform Doc ument. forms [0]
For (var I = 0; 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 return TRUE or FALSE if selected)
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 value to be selected)
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 the number of hosts.
41. Define a Date variable: var today = new Date ();
42. Date function list: dateObj. getTime () get time, dateObj. getYear () Get year, dateObj. getFullYear () get four-digit year, dateObj. getMonth () Get
By month, dateObj. getDate () gets the day, dateObj. getDay () gets the date, dateObj. getHours () gets the hour, dateObj. getMinutes () gets
Minute, dateObj. getSeconds () to get the second, dateObj. setTime (value) to set the time, dateObj. setYear (val) to set the year, dateObj. setMonth (val) to set
Month, dateObj. setDate (val) setting day, dateObj. setDay (val) setting day of the week, dateObj. setHours setting hour, dateObj. setMinutes (val) Setting
Minute, 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 JS functions in a hyperlink, use the following name to start with: (javas alias :).
48. Do not execute this js in the old browser:

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.