107 Common statements for JavaScript

Source: Internet
Author: User
Tags date object definition expression function definition string variable window

Core tips: JavaScript Common sentence Collection

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 name and value of the element in the form: document.getElementById ("ID number of elements in the form"). Name (or value)
6. A lowercase capitalization JS:document.getElementById ("Output"). Value = document.getElementById ("input"). Value.touppercase ();
Value type 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 connected with the character story.
The comparison operators in 12.JS are: = = equals,!= is not equal to, >=,. <=
13.JS declaring variable use: var to declare
Decision statement structure in 14.JS: if (condition) {}else{}
Loop structure in 15.JS: for ([Initial expression];[ Condition]; [Upadte expression]) {Inside loop}
16. The order of the circular abort is: break
function definition in 17.JS: function functionname ([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 Window window.open (), close a window: window.close (), window itself: Self
20. The setting of the form column: window.status= "character";
21. Pop-up Message: Window.alert ("character");
22. Pop-up Confirm 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 check: document.forms[0].checkthis.checked (The Checked property represents whether checked returns true or false)
32. Radio button Group (the name of the radio button must be the same): the length of a radio button group Document.forms[0].groupname.length
33. Radio button Group to determine whether the selected is also used checked.
34. 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 make sure the selected value)
35. Definition of string: var myString = new String ("This is Lightsword");
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 the description was not found.
38. Takes a character at a specified position in the string: Stringa.charat (9);
39. Remove the substring from the specified start and end point in the string: stringa.substring (2,6);
40. Mathematical function: Math.PI (return pi), Math.sqrt2 (return to the root), Math.max (value1,value2) returns the most value in the two number, Math.pow (value1,10) return

10 value1, Math.Round (value1) rounding function, Math.floor (Math.random () * (n 1)) returns random number
41. Define date variables: var today = new Date ();
42. Date Function List: Dateobj.gettime () Get Time, dateobj.getyear () Get the Year, Dateobj.getfullyear () get four-digit year, Dateobj.getmonth ()

To the month, Dateobj.getdate () Gets the day, Dateobj.getday () Gets the date, dateobj.gethours () Gets the Hour, dateobj.getminutes () gets

Minutes, dateobj.getseconds () Get seconds, dateobj.settime (value) set time, Dateobj.setyear (Val) set year, Dateobj.setmonth (val) settings

Month, Dateobj.setdate (Val) Set day, Dateobj.setday (val) set days of the week, Dateobj.sethours set hours, Dateobj.setminutes (val) settings

Min, Dateobj.setseconds (val) Set seconds [Focus: 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 start with the following function name
48. Do not execute this JS in the old browser: <!--//-->
49. Refer to a file-style JS: <script type= "Text/javascript" src= "Aaa.js" > </script >
50. Specify HTML to display in browsers that do not support scripting: <noscript > </noscript >
51. When the chain and onclick events are sometimes, the old version of the browser turned to a.html, otherwise turn to b.html. Example: <a href= "a.html" >DFSADF </a >

1 2 Next page > full text reading tips: Try "←→" button, turn the page more convenient Oh!

[1] [2] Next page



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.