Common JavaScript Functions (2)

Source: Internet
Author: User
1.doc ument. write (""); Output Statement 2. the 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 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 (); 7. value types in JS: String, number, Boolean, null, object, function8.js convert numeric type to numeric type: parseint (), Parsefloat () 9. convert numbers in JS to numeric: ("" + variable) 10. the string length in JS is: (length) 11. the character in JS is connected with the character using the plus sign. 12. comparison operators in JS include: = equals ,! = Not equal to,>, >=, <. <= 13. use VaR to declare variables in JS. 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 for loop abort is: Function Definition in break17.js: function functionname ([parameter],...) {statement [s]} 18. when multiple form forms appear in the file. document. forms [0], document. forms [1] instead. 19. window: open a window. open (), close a window: window. close (), window itself: self20. setting of the status bar: window. status = "character"; 21. window. ale RT ("character"); 22. pop-up confirmation box: window. confirm (); 23. enter window. prompt (); 24. specify the position of the currently displayed link: window. location. href = "url" 25. number of All Forms in the form: document. forms. length26. 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-type members in the form to NULL: var form = invalid argument Doc ument. forms [0] For (VAR I = 0; I <form. elements. length; I ++) {If (form. elemen TS [I]. type = "text") {form. elements [I]. value = "" ;}} 31. check button in JS to determine whether to select: 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): the length of the single-choice button group is document. forms [0]. groupname. length33. the value of the checked.34. drop-down list box is: document. forms [0]. selectname. options [N]. value (N is sometimes added with the name of the drop-down list box. selectedindex to determine the selected value) 35. string definition: var mystring = new string ("this is lightsword"); 36. string to uppercase: string. Touppercase (); 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. obtain the substring stringa that specifies the start and end points in the string. substring (2, 6); 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 random number 41. defines the date type 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, dat Eobj. 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"]. objfu Ncvarname, framename. objfuncvarname44.parent represents the parent object, and top represents the top object 45. open the parent window of the subwindow: opener46. indicates the current location: this47. when calling the JS function in the hyperlink, start with (JavaScript :) 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 = "AAA. JS "> </SCRIPT> 50. specify the HTML displayed in a browser that does not support scripts: <NoScript> </NoScript> 51.when both the hyperchain and onclickevent are available, the browser of the old user turns to a.html, And the browser turns to B .html when the negative user turns to B .html. example: <a href = "a.html" onclick = "location.href0000' 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, and line feed in urierror53.js: \ n54. Full Screen Window 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 the elements in its lower layer 56. focus sequence in JS: document. getelementbyid ("form element "). tabindex = 157. 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 configurable Elements Whether it can be modified, iscontenteditable returns whether it can be modified. 60. isdisabled determines whether it is disabled. disabled sets the forbidden status 61. length to get the length, return the integer value 62. addbehavior () is an external function file called by JS. Its extension is. htc63.window. focus () to make the current window 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 )"). length68.js consists of two forms: modal and non-modal. window. showmodaldialog (), window. showmodeless () 69. set the text in the status bar: window. status = 'Text', default status bar text settings: window. defaultstatus = 'text. '; 70. add to favorites: external. addFavorite ("http://www.xrss.cn", "jaskdlf"); 71. when a script error occurs in JS, do not perform any operation: window. onerror = donothing; syntax for specifying the error handle: window. onerror = handleerror; 72. specify the parent window currently opened in JS: window. opener, supporting opener. opener.... 73. self in JS refers to the current window 74. JS status bar display content: window. status = "content" 75. in JS, top refers to the top framework 76 in the framework set. close the current window in JS: window. close (); 77. if (confirm ("Are you sure? ") {Alert (" OK ");} else {alert (" not OK ");} 78. window redirection in JS: window. navigate ("http://www.sina.com.cn"); 79. JS print: window. print () 80. JS prompt input box: window. prompt ("message", "defaultreply"); 81. window scroll bar in JS: window. scroll (x, y) 82. in JS, the window is rolled to the position: window. set the time interval in scrollby83.js: the mode in setinterval ("expr", msecdelay), setinterval (funcref, msecdelay), or settimeout84.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. 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" specify 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", start position), returns the first position that appears (calculated from 0) 97. string. lastindexof (searchstring [, startindex]) location where the last error occurred. 98. string. match (regexpression) to determine whether the characters match. 99. string. replace (regexpression, replacestring) replaces the existing string. 100. string. split 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 (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. key word for defining constants: const, key word for defining variables: VaR

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.