JS function usage guide

  • 2020-03-30 04:20:15
  • OfStack

1. The document. The write (" "); Output statements

The comment in 2.JS is //

3. The traditional HTML document order is :document-> HTML - > (the head, body)

4. The DOM order in a browser window is :window-> (the navigator, screen, the history, the location, the document)

5. Get the name and value of the elements in the form: document.getelementbyid (" ID number of elements in the form ").name(or value)

6. A lowercase toUpperCase JS: document.getelementbyid ("output").value = document.getelementbyid ("input").value.touppercase ();

7. The value types of JS: String, Number, Boolean, Null, Object, Function

ParseInt (),parseFloat(), parseInt(),parseFloat()

Convert Numbers to characters in 9.JS :(""+ variable)

The length of the fetch string in 10.JS is :(length)

Characters in 11.JS are concatenated with characters using the + sign.

The comparison operator in 12.JS is :== == =! Is not equal to,> , > =, < . < =

JS declaration variables are declared using :var

JS :if(condition){}else{}

For ([initial expression]; [condition]; [upadte expression]) {inside loop}

16. The command to abort the loop is break

Function functionName([parameter],...) {the statement [s]}

18. When multiple forms appear in a file,document.forms[0] and document.forms[1] can be used instead.

Window.open (), close a window :window.close(), window itself :self

20. Setting of status bar :window.status=" character ";

Window. Alert (" character ");

22. Window. Confirm ();

23. Window. Prompt ();

24. Specify the location of the currently displayed link :window.location.href="URL"

25. Takes the number of all forms in the form :document.forms.length

Close the output stream of the document :document.close();

27. String appended concatenation :+=

Create a document element: document.createelement (), document.createtextnode ()

Method to get the element: document.getelementbyid ()

30. Set the value of all text-type members in the form to null:

  Var form = window. The document. The forms [0]

  For (var I = 0; I< Form. Elements. Length; I++) {

        If (the form elements [I] type = = "text") {

                Form. The elements [I] value = "";

        }

  }

31. Check button in JS :document.forms[0]. Checkthis.checked

32. Radio button group (the name of the radio button must be the same): takes the length of the radio button group document.forms[0].groupname.length

Checked is also used to determine whether the radio button group is checked.

Document.forms [0]. Selectname.options [n]. Value (n sometimes USES the name of the drop-down box plus.selectedindex to determine the selected value)

Var myString = new String("This is lightsword");

36. String converted toUpperCase: string.touppercase (); String.tolowercase ();

Returns the position of String2 in String1: string1.indexof ("String2")! =-1 means we didn't find it.

38. Takes a character at the specified position in the string: stringa.charat (9);

39. Takes the substring from the string that specifies the starting and ending points: stringa. substring(2,6);

Math functions: math.pi (returns PI), math.sqrt2 (returns the square root), math.max (value1,value2) returns the highest value of two Numbers, math.pow (value1,10) returns value1 to the tenth power, math.round (value1) rounds the function, math.floor (math.random ()*(n+1)) returns a random number

41. Var today = new Date();

Dateobj. getTime() gets the time, dateobj. getYear() gets the year, dateobj. getFullYear() gets the four-digit year, dateobj. getMonth() gets the month, and dateobj. getDate() gets the four-digit year

Dateobj. getDay() gets the date, dateobj. getHours() gets the hour, dateobj. getMinutes() gets the minutes, dateobj. getSeconds() gets the seconds, dateobj. setTime(value) sets the time, dateobj. setYear(val) sets the year, dateobj. setMonth(val) sets the month, dateobj. setDate(val) sets the day,dateO Bj. setDay(val) setting day of the week, dateobj. setHours setting hours, dateobj. setMinutes(val) setting minutes, dateobj. setSeconds(val) setting seconds   [note: this date is counted from 0]

43. The representation of FRAME: [Windows] frames [n]. ObjFuncVarName, frames [r]. "frameName ObjFuncVarName, frameName. ObjFuncVarName

Parent represents the parent object and top represents the top object

The parent window that opens the child window is :opener

46. Indicates the current position :this

When calling a JS function in a hyperlink, start with :(javascript:) followed by the function name

Do not execute this JS:< ! -           / / - >

Reference to a file JS:< The script type = "text/javascript" SRC = "aaa. Js >" < / script>

51. When both hyperlink and ONCLICK events occur, the older version of the browser moves to a.html, or to b.html. A href = "a.h HTML" > Dfsadf< / a>

52. JS built-in objects are: Array, Boolean, Date, and the Error, EvalError, Function, Math, Number, Object, RangeError, ReferenceError, RegExp, String, SyntaxError, TypeError, URIError

Line break in 53.js :\n

54. Window full screen size :< Script> The function fullScreen () {enclosing moveTo (0, 0); Enclosing outerWidth = screen. AvailWidth; Enclosing outerHeight = screen. AvailHeight; }

Window. Maximize = fullScreen; < / script>

All in 55.js represents all of its underlying elements

Focus order in 56.js: document.getelementbyid (" form element ").tabindex = 1

57. The value of the innerHTML is the value of the form element: for example < P id = "para" >" How are < Em> You< / em>" < / p> , then the value of innerHTML is :how are < Em> You< / em>

58. The value of the innerTEXT is the same as the one above, except that it does not put < Em> This tag is displayed.

59. ContentEditable sets whether the element can be modified, and isContentEditable returns the modifiable state.

60. IsDisabled determines whether it isa disabled state. Disabled sets the disabled state

Length gets the length and returns the integer value

62.addbehavior () is an external function file called by JS with an extension of.htc

63.window.focus() puts the current window in front of all other Windows.

64. Blur () means to lose FOCUS.

65. Select () means that the element is selected.

66. Prevent the user from entering text into the text box:

67. Take the number of tags("div(or other HTML tag)") that the element appears in the page :document.all.tags("div(or other HTML tag)").length

JS is divided into two types of form output: modal and non-modal. Window. showModaldialog(),window.showModeless()

69. Setting of status bar text :window.status=' text '; setting of defaultStatus bar text: window.defaultstatus =' text ';

Add to favorites :external.AddFavorite(") , & quot; Jaskdlf) ");

JS does not do anything when it encounters a script error :window.onerror = doNothing; The syntax for specifying the error handle is window.onerror = handleError;

Self in 73.js refers to the current window

Window. status=" content"

Top in 75.js refers to the top frame in the set of frames

76.js :window.close();

77.js :if(confirm("Are you sure?") )) {alert (" ok "); } else {alert (" Not Ok "); }

Window redirect in 78.js :window.navigate(" (link: http://www.sina.com.cn) ");

JS :window.print()

Window. prompt("message","defaultReply");

Window. scroll(x,y)

The window in 82.js scrolls to its position :window.scrollby

83.js :setInterval("expr",msecDelay) or setInterval(funcRef,msecDelay) or setTimeout

84.js mode is displayed in IE4+ line, not in NN :showModalDialog("URL"[,arguments][,features]);

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 first called :onload()

File handle called when the form is closed :onunload()

Properties of 88.window.location: protocol(HTTP :),hostname(link: http://www.example.com),port(80),host(www.example.com:80), and pathname(www.example.com:80). / a/a.h tml") , hash (& quot; #giantGizmo) ", refers to jump to the corresponding anchor),href(full information)

89. The window. The location. Reload () to refresh the current page.

89-1. Parent. Location. Reload () refreshes the parent object (for the framework)

89-2. Opener. Location. Reload () refreshes parent window object (for single open window)

89-3. Top.location.reload () refreshes the topmost object (for multiple Windows)

90.window.history.back(),window.history.forward(),window.history.go

Output of 91. Document.write () without newline,document.writeln() newline output

92. The document. The body. NoWrap = true; Prevent link text from breaking lines.

Variable name. CharAt (place), take the character of the place of the variable.

94." ABC ". CharCodeAt (number), returns the ASCii value of the number of characters.

95. String concatenation :string.concat(string2), or concatenation with +=

Variables. IndexOf (" character ", starting position), returns the first position (calculated from 0)

Last position of lastIndexOf(searchString[,startIndex]).

98.string.match(regExpression) to determine whether the characters match.

99. String. Replace (regExpression replaceString) replace an existing string.

100. String. Split (separator) returns an array of stored values.

101.string.substr(start[,length]) takes a string from which bit to the specified length.

102.string.tolowercase () makes the string all lowercase.

103.string.touppercase () capitalizes all characters.

ParseInt (string[,radix)) is cast to integer.

105. ParseFloat (string[,radix]) is cast to floating-point.

106. IsNaN (variable): tests for numeric type.

107. Define the constant keyword :const, define the variable keyword :var

In the end or not enough to make up for a hundred orders eight will, small regret it, friends help to make up also line ah?


Related articles: