111 statements commonly used in JavaScript

Source: Internet
Author: User
Tags function definition mathematical functions set time setinterval time interval

1.document.write (""); Output statement

The annotation in 2.JS is//

3. The traditional HTML document order is:

Document->html-> (Head,body)

4. The DOM order in a browser window is:

Window-> (navigator,screen,history,location,document)

5. Get the names and values of the elements in the form:

document.getElementById (the ID number of the element in the form). Name (or value)

6. A lowercase to uppercase JS:

document.getElementById ("Output"). Value=document.getelementbyid ("Input"). Value.touppercase ();

Value types in 7.JS:

String,number,boolean,null,object,function

The character type in 8.JS converts to a numeric type:

parseint (), parsefloat ()

Converts numbers in 9.JS to character types:

("" variable)

The length of the string in 10.JS is:

(length)

The characters in 11.JS are used with the character story connection number.

The comparison operators in 12.JS are:

= = equals,!= not equal, >,>=,<.<=

Declare variable use in 13.JS:

var to make a declaration

The structure of judgment statement in 14.JS:

if (condition) {}else{}

Cyclic structure in 15.JS:

for ([Initial expression];[ Condition]; [Upadteexpression]) {Inside loop}

16. The order of the circular suspension is:

Break

The function definition in 17.JS:

Functionfunctionname ([parameter],...) {Statement[s]}

18. When multiple form forms appear in a file, they can be replaced with document.forms[0],document.forms[1].

19. Window:

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

20. Status Bar Settings:

window.status= "character";

21. Pop-up Prompt message:

Window.alert ("character");

22. Pop-up Confirmation Box:

Window.confirm ();

23. Pop-up Input Prompt box:

Window.prompt ();

24. Specify the location of the currently displayed link:

window.location.href= "URL"

25. Remove the number of 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. Methods of obtaining elements:

document.getElementById ()

30. Set the value of all text types in the form to null:

var form = Window.document.forms[0]

for (var i = 0; i<form.elements.length;i) {

if (Form.elements.type = = "Text") {

Form.elements.value = "";

}

}

31. Check the button in JS to determine whether to select:

Document.forms[0].checkthis.checked

(The Checked property indicates whether to select return True or FALSE)

32. Radio button Group (the name of the radio button must be the same):

Take the length of the radio button group Document.forms[0].groupname.length

33. Radio button Group to determine whether the selected is also used checked.

34. The value of the Drop-down list box:

Document.forms[0].selectname.options[n].value

(n sometimes with a drop-down list box name plus. SelectedIndex to determine which value is selected)

35. Definition of string:

var myString = new String ("This Islightsword");

36. String to uppercase:

String.touppercase (); The string is turned to lowercase: string.tolowercase ();

37. Returns the position where string 2 appears in string 1:

String1.indexof ("String2″")!=-1 is not found.

38. Takes a character at a specified position in the string:

Stringa.charat (9);

39. Remove the substring of the specified start and end point in the string:

Stringa.substring (2,6);

40. Mathematical Functions:

Math.PI (return pi), Math.sqrt2 (return to the root), Math.max (value1,value2) return two number of

Most in value, Math.pow (value1,10) returns the value1 10-second square, Math.Round (value1) rounding function,

Math.floor (Math.random () * (n 1)) returns random numbers

41. Define date-type variables:

var today = new Date ();

42. List of date functions:

Dateobj.gettime () Gets the time, dateobj.getyear () Gets the year, Dateobj.getfullyear () gets four-bit years,

Dateobj.getmonth () Gets the month, dateobj.getdate () Gets the day, Dateobj.getday () Gets the date,

Dateobj.gethours () Gets the Hour, dateobj.getminutes () Gets the minute, dateobj.getseconds () gets the second,

Dateobj.settime (value) set time, Dateobj.setyear (Val) set year,

Dateobj.setmonth (Val) set month, Dateobj.setdate (Val) Set day,

Dateobj.setday (val) sets the day of the week, Dateobj.sethours set hours, Dateobj.setminutes (val) set,

Dateobj.setseconds (val) Set seconds [Note: This date time starts at 0]

43.FRAME representation:

[Window.] Frames[n]. objfuncvarname,frames["FrameName"]. Objfuncvarname,framename.objfuncvarname

44.parent represents the Father object, top represents the topmost object

45. Open child window's parent window is: opener

46. Represents the current location: this

47. When calling the JS function in a hyperlink: (JavaScript

To begin with the following letter of function name

48. Do not perform this js:<!–//–> in the old browser

49. Refer to a file-type js:<scripttype= "Text/javascript" src= "Aaa.js" ></script>

50. Specify html:<noscript></noscript> that are displayed in browsers that do not support scripting

51. When the chain and onclick events are sometimes, the old version of the browser turned to a.html, otherwise turned to b.html.

Example: <ahref= "a.html" onclick= "location.href= ' b.html '; return false" >dfsadf</a>

52.JS of built-in objects are:

Array,boolean,date,error,evalerror,

Function,math,number,object,rangeerror,referenceerror,

Regexp,string,syntaxerror,typeerror,urierror

Line wrapping in 53.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>

All of the 55.JS represents all the elements of its lower layer

Focus order in 56.JS: document.getElementById ("form Element"). tabindex= 1

The value of 57.innerHTML is the value of the form element:

such as <pid= "para" > "How are <em>you</em>" </p>, the innerHTML value is: Howare <em>you</em>

The value of 58.innerTEXT is the same as above, except that the <em> tag is not displayed.

59.contentEditable can set whether the element can be modified, iscontenteditable returns whether the state can be modified.

60.isDisabled determines whether it is a prohibited state. Disabled setting prohibit state

61.length get length, return integer value

62.addBehavior () is a JS called external function file whose extension is. htc

63.window.focus () causes the current window to precede all windows.

64.blur () refers to the loss of focus.

65.select () refers to the element as a selected state.

66. Prevent users from entering text in the text box:

Onfocus= "This.blur ()"

67. Remove the number of occurrences of this element on the page:

Document.all.tags ("div (or other HTML tag)"). length

There are two forms of output in 68.JS: Modal and non-modal.

window.showModalDialog (), window.showmodeless ()

69. Status bar Text settings:

window.status= ' text ', default status bar text settings: window.defaultstatus = ' text. '

70. Add to Favorites:

External. Addfavorite ("http://meil.cnblogs.com";, "Jaskdlf");

No action is encountered in 71.JS for scripting errors:

Window.onerror = donothing; The syntax for the specified error handle is: Window.onerror = HandleError;

The parent window of the currently open window is specified in 72.JS:

Window.opener, Support Opener.opener ... The multiplicity continues.

Self in 73.JS refers to the current window

74.JS status bar display content: window.status= "Content"

Top in 75.JS refers to the topmost frame in the frameset

Close the current window in 76.JS: Window.close ();

77.JS box for confirmation: if (Confirm ("areyou sure?") {Alert ("OK");} Else{alert ("not OK");}

Window redirection in 78.JS: Window.navigate ("http://meil.cnblogs.com";);

Printing in 79.JS: Window.print ()

80.JS prompt input box: window.prompt ("message", "defaultreply");

Window scroll bar in 81.JS: Window.Scroll (x,y)

The window in 82.JS scrolls to position: Window.scrollby

Set time interval in 83.JS: setinterval ("expr", Msecdelay) or setinterval (Funcref,msecdelay) or settimeout

The modal in 84.JS is displayed in the IE4 line, not in nn: ShowModalDialog ("URL" [, Arguments][,features]);

Handle used before exiting in 85.JS:

function Verifyclose () {event.returnvalue= "wereally" like you and hope your'll stay longer. ";}} Window.=verifyclose;

86. File handle to use when the form is first called: onload ()

87. File handle to call when form closes: OnUnload ()

Properties of 88.window.location:

Protocol (http:), hostname (www.example.com), port (+), host (WWW.EXAMPLE.COM:80),

Pathname ("/a/a.html"), hash ("#giantGizmo", meaning jump to the corresponding anchor), href (All information)

89.window.location.reload () refreshes the current page.

90.window.history.back () returns to the previous page, Window.history.forward () returns to the next page,

Window.history.go (return to page, also use visited URLs)

91.document.write () No line-wrapping output, Document.writeln () line-wrapping output

92.document.body.nowrap=true prevents link text from wrapping.

93. Variable name. CharAt (ordinal), take the first few characters of the variable.

The "ABC". charCodeAt (ordinal number) returns the ASCII value of the first few characters.

95. String Connection: String.Concat (string2), or connect with =

96. Variable. IndexOf ("character", starting position), returns the first occurrence of the position (calculated starting from 0)

97.string.lastindexof (Searchstring[,startindex]) where the last occurrence occurred.

98.string.match (regexpression) to determine whether characters match.

99.string.replace (regexpression,replacestring) replaces the existing string.

100.string.split (delimiter) returns an array to store the value.

101.string.substr (Start[,length]) takes a string from the first few to the specified length.

102.string.tolowercase () causes the string to be all lowercase.

103.string.touppercase () turns all characters into uppercase.

104.parseInt (String[,radix)] forces the conversion to an integral type.

105.parseFloat (String[,radix]) is cast to a floating-point type.

106.isNaN (variable): test for numeric type.

107. Define Constants Keywords: const, define variables keywords: var

108.window.location.reload () refreshes the current page

109.parent.location.reload () Refreshes the Father object (for frames)

110.opener.location.reload () Refreshes the parent window object (for a single open window)

111.top.location.reload () Refreshes the topmost object (for multiple windows)

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.