Common JS Functions

Source: Internet
Author: User
Tags exit in

1.doc-ument. Write (""); Output statement
2. Comments in JS are //
3. The traditional HTML document sequence is: Doc-ument-> HTML-> (Head, body)
4. the DOM sequence in a browser window is: window-> (navigator, screen, history, location, doc-ument)
5. Get the name and value of the element in the form: doc-ument.getElementById ("ID of the element in the form"). Name (or value)
6. A lowercase to uppercase JS: doc-ument.getElementById ("output"). value = doc-ument.getElementById ("I
Nput "). 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 expression]; [condition]; [upadte expression]) {inside loop}
16. The command for loop abort is break.
17. Function Definition in JS: function functionname ([parameter],...)
18. When multiple form forms appear in the file. You can use doc-ument.forms [0], doc-ument.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 = "url"
25. Fetch the number of all forms in the form: doc-ument.forms.length
26. Close the output stream of the document: doc-ument.close ();
27. String append connector: + =
28. Create a document element: doc-ument.createElement (), doc-ument.createTextNode ()
29. method for getting elements: doc-ument.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 the button in JS to determine whether to select: doc-ument.forms [0]. Checkthis. Checked (the checked attribute indicates whether to select
Returns true or false)
32. radio button group (single button name must be the same): Take the length of the radio button group doc-ument.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: doc-ument.forms [0]. selectname. Options [N]. Value (N sometimes adds. sel with the name of the drop-down list box
Ectedindex 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 (returns the square), and math. Max (value1, value2) return the most of the two numbers.
In the value, 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 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 month, dateobj. getdate () get day, dateobj. getday () Get date, dat
Hour for eobj. gethours (), hour for dateobj. getminutes (), second for dateobj. getseconds (), and second for dateobj. setti
Me (value) setting time, dateobj. setyear (VAL) setting year, dateobj. setmonth (VAL) Setting month, dateobj. setdate (VA
L) set the day, dateobj. setday (VAL), dateobj. sethours, and dateobj. setminutes (VAL,
Dateobj. setseconds (VAL) sets the second. [Note: this date and time start from 0]
43. Frame representation: [window.] frames [N]. objfuncvarname, frames ["framename"]. objfuncvarn
Ame, 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:
50. Specify the HTML displayed in a browser that does not support scripts:
51.when there are both hyperchains and onclickrelated items, the browser of the old user changes to a.html, And the browser changes to B .html if there is no such thing. Example: dfsadf
52. js built-in objects include: array, Boolean, date, error, Eval error, function, math, number, object, rangeerror,
Referenceerror, Regexp, String, syntaxerror, typeerror, urierror
Line feed in 53. JS: \ n
54. Full Screen Window Size:
All in 55. js represents all the elements in its lower layer.
Focus sequence in 56. JS: doc-ument.getElementByid ("form element"). tabindex = 1
57. The value of innerhtml is the value of the form element: for example
"How are you"

, The value of innerhtml is: how are you
58. The value of innertext is the same as the above, but it will not be 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: doc-ument.all.tags ("Div (or other HTML Tag)"). 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.dannyg.com/" t;, "jaskdlf ");
71. js does not perform any operation when it encounters a script error: window. onerror = donothing; syntax for specifying the error handle: window. On
Error = 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? ") Else {alert (" not OK ");}
Window redirection in 78. JS: window. navigate ("http://www.sina.com.cn /");
-Window. navigate ("? "+ Var test );
When there are too many threads, there are too many other threads
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 settimeou
T
The Mode in 84. JS is displayed in ie4 + lines, but not in NN: showmodaldialog ("url" [, arguments] [, features]);
Handle used before exit in 85. JS: function verifyclose () {event. returnvalue = "We really like you and Ho
PE 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 (example.com), Port (80), host (E
Xample.com: 80), pathname ("/A/a.html"), hash ("# giantgizmo", refers to jump to the corresponding anchor), href (all emails
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 (returns
Page number. You can also use the accessed URL)
91.doc-ument. Write () output without line feed, doc-ument.write Ln () line feed output
92.doc-ument. Body. nowrap = true; prevent link text lines.
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 () converts all strings to lowercase.
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

Use regular expressions to restrict text boxes to enter only numbers, decimal places, English letters, Chinese characters, and other types of code

1. Only numeric code can be entered in the text box (decimal point cannot be entered)
<Input onkeyup = "this. value = This. value. replace (/\ D/g, '')" onafterpaste = "this. value = This. value. replace (/\ D/g, '')">

2. Only numbers can be entered, and decimal points can be entered.
<Input onkeyup = "If (isnan (value) Execcommand ('undo ')" onafterpaste = "If (isnan (value) Execcommand ('undo')">
<Input name = txt1 onchange = "If (/\ D /. test (this. value) {alert ('only numbers allowed '); this. value = '';}">

3. Number and decimal point method 2
<Input type = text t_value = "" o_value = "" onkeypress = "If (! This. value. Match (/^ [\ + \-]? \ D *? \.? \ D *? $/) This. value = This. t_value; else this. t_value = This. value; If (this. value. Match (/^ (? : [\ + \-]? \ D + (? : \. \ D + )?)? $/) This. o_value = This. Value "onkeyup =" If (! This. value. Match (/^ [\ + \-]? \ D *? \.? \ D *? $/) This. value = This. t_value; else this. t_value = This. value; If (this. value. Match (/^ (? : [\ + \-]? \ D + (? : \. \ D + )?)? $/) This. o_value = This. Value "onblur =" If (! This. value. Match (/^ (? : [\ + \-]? \ D + (? : \. \ D + )? | \. \ D *?)? $/) This. value = This. o_value; else {If (this. value. match (/^ \. \ D + $/) This. value = 0 + this. value; If (this. value. match (/^ \. $/) This. value = 0; this. o_value = This. value} ">

4. Only letters and Chinese characters can be entered
<Input onkeyup = "value = value. replace (/[\ D]/g, '')" onbeforepaste = "clipboardData. setdata ('text', clipboardData. getdata ('text '). replace (/[\ D]/g, '')" maxlength = 10 name = "Numbers">

5. Only English letters and numbers are allowed. Chinese characters are not allowed.
<Input onkeyup = "value = value. Replace (/[^ \ W \. \/]/ig,'') ">

6. Only numbers and English letters can be entered. <font color = "red"> Chun </font>
<Input onkeyup = "value = value. Replace (/[^ \ d | Chun]/g,'') ">

7. After the decimal point, you can enter a maximum of two digits (numbers and Chinese characters). You cannot enter letters or operator numbers:
<Input onkeypress = "If (event. keycode <48 | event. keycode> 57) & event. keycode! = 46 |/\. \ D $/. Test (value) event. returnvalue = false ">

8. A maximum of two digits (numbers, letters, and Chinese characters) can be entered after the decimal point. You can enter the operator number:
<Input onkeyup = "this. value = This. value. replace (/^ (\-) * (\ D + )\. (\ D ). * $/, '$1 $2. $ 3') ">

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.