JavaScript Tips-js Tips collection (RPM)

Source: Internet
Author: User
Tags setinterval tagname

This article was reproduced from: http://blog.csdn.net/ocean20/article/details/2498699

Each item is JS in the small tricks, but very practical!
1.document.write (""); Output statement
The comments in the 2.JS are//
3. 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 the element in the form"). Name (or value)
6. A lowercase capitalization JS:document.getElementById ("Output"). Value = document.getElementById ("I
Nput "). Value.touppercase ();
Value types in 7.JS: string,number,boolean,null,object,function
Conversion of character types in 8.JS to numeric: parseint (), parsefloat ()
Numbers in 9.JS converted to character: ("" + variable)
The length of the string in 10.JS is: (length)
The characters in 11.JS are connected to the word typeface using the + sign.
The comparison operator in 12.JS has: = = equals,! = does not equal, >,>=,<.<=
Declaring variables in 13.JS using: var for declaration
Judgment statement structure in 14.JS: if (condition) {}else{}
Loop structure in 15.JS: for ([Initial expression];[ Condition]; [Upadte expression]) {Inside loop}
16. The Circular abort command is: Break
Functions definition in 17.JS: function functionname ([parameter],...)
18. When multiple form forms appear in a file, you can use document.forms[0],document.forms[1] instead.
19. Window: Open Window window.open (), close a window: window.close (), window itself: Self
20. Setting of the status bar: window.status= "character";
21. Popup Message: Window.alert ("character");
22. Pop-Up Confirmation box: window.confirm ();
23. Popup Input Prompt Box: window.prompt ();
24. Specify the location of the current display link: window.location.href= "URL"
25. Remove the number of all 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. Method of getting elements: document.getElementById ()
30. Set the value of the members of all text types in the form to be null:
var form = Window.document.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: Document.forms[0].checkthis.checked (Checked property represents whether to select
Returns TRUE or false)
32. Radio button Group (the name of the radio button must be the same): the length of the radio button group Document.forms[0].groupname.length
33. Radio button Group to determine whether to be 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. sel
Ectedindex to determine the selected value)
35. Definition of the string: var myString = new String ("This is Lightsword");
36. Turn the string into uppercase: String.touppercase (); The string is converted 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. Take a character at the specified position in the string: Stringa.charat (9);
39. Remove the substring that specifies the start and end point in the string: stringa.substring (2,6);
40. Mathematical function: Math.PI (return to PI), Math.sqrt2 (return to root), Math.max (value1,value2) returns two number of the most
In the value, Math.pow (value1,10) returns value1 10 times, Math.Round (value1) rounding function, Math.floor (math.ra
Ndom () * (n+1)) return random number
41. Define date type variable: var today = new Date ();
42. Date Function List: Dateobj.gettime () Gets the time, dateobj.getyear () Gets the year, dateobj.getfullyear () gets
Four-bit year, dateobj.getmonth () Gets the month, dateobj.getdate () Gets the day, Dateobj.getday () Gets the date a few, dat
Eobj.gethours () Gets the Hour, dateobj.getminutes () gets points, dateobj.getseconds () gets seconds, Dateobj.setti
Me (value) set the time, Dateobj.setyear (Val) set year, Dateobj.setmonth (Val) set month, Dateobj.setdate (VA
L) Set the date, Dateobj.setday (val) Set the day of the week, Dateobj.sethours set the Hour, Dateobj.setminutes (Val) set points,
Dateobj.setseconds (val) Set seconds [Note: This date time starts from 0]
43.FRAME representation: [window.] Frames[n]. objfuncvarname,frames["FrameName"]. Objfuncvarn
Ame,framename.objfuncvarname
44.parent represents the parent object, top represents the topmost object
45. Open the child window's parent window as: opener
46. Indicates the location currently belongs to: this
47. When invoking the JS function in the hyperlink: (JavaScript:) to start with the name of the Add function
48. Do not execute this JS in the old browser:
49. Refer to a file-type JS:
50. Specify the HTML that is displayed in browsers that do not support scripting:
51. When both the hyperlink and the OnClick event are sometimes, the old version of the browser turns to a.html, otherwise turns to b.html. Example: DFSADF
The 52.JS built-in objects are: Array,boolean,date,error,evalerror,function,math,number,object,rangeerror,
Referenceerror,regexp,string,syntaxerror,typeerror,urierror
Line break in 53.JS:/n
54. Window Full Screen Size:
All in 55.JS represents all 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:
"How is"

, then the value of innerHTML is: how is You
The value of 58.innerTEXT is the same as above, except that it does not show the mark.
59.contentEditable can set whether the element can be modified, iscontenteditable returns whether the state can be modified.
60.isDisabled determines whether the status is forbidden. Disabled setting the Forbidden State
61.length get length, return integral type 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. In contrast to focus ().
65.select () refers to elements that are selected.
66. Prevent user from entering text in text box: onfocus= "This.blur ()"
67. Remove the number of occurrences of the element in 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 ', the default status bar text settings: window.defaultstatus = ' text. ';
70. Add to Favorites: External. Addfavorite ("http://www.dannyg.com"T;," JASKDLF ");
Do not do anything when a script error is encountered in 71.JS: Window.onerror = doNothing; The syntax for specifying an error handle is: Window.on
Error = HandleError;
The parent window of the currently open window is specified in 72.JS: Window.opener, Support Opener.opener ... The multiplicity of continuation.
The 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 frame set.
Close the current window in 76.JS: Window.close ();
box for confirmation in 77.JS: if (Confirm ("Is you sure?")) Else{alert ("not OK");}
Window redirection in 78.JS: Window.navigate ("http://www.sina.com.cn"t;);
Printed in 79.JS: Window.print ()
Prompt input box in 80.JS: Window.prompt ("message", "defaultreply");
Window scroll bar in 81.JS: Window.Scroll (x, y)
window in 82.JS scroll to position: Window.scrollby
Set time interval in 83.JS: setinterval ("expr", Msecdelay) or setinterval (Funcref,msecdelay) or Settimeou
T
Modal display in 84.JS in ie4+ line, not in nn: ShowModalDialog ("URL" [, Arguments][,features]);
Handle used before exiting in 85.JS: function Verifyclose () {event.returnvalue= "We really like you and Ho
PE you'll stay longer. ";}} Window.onbeforeunload=verifyclose;
86. File handle used when the form is first called: onload ()
87. File handle called when the form is closed: onunload ()
88.window.location Properties: Protocol (http:), hostname (example.com), port, host (E
XAMPLE.COM:80), pathname ("/a/a.html"), hash ("#giantGizmo", refers to jump to the corresponding anchor), href (all the letters
Income
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
Page, you can also use the URL you have visited)
91.document.write () output with no newline, Document.writeln () line-wrapping output
92.document.body.nowrap=true; Prevent link text from wrapping.
93. Variable name. charAt (the first few), take the character of the variable.
94. "ABC". charCodeAt (the first few), 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]) The last occurrence of the position.
98.string.match (regexpression) to determine if the characters match.
99.string.replace (regexpression,replacestring) replaces the existing string.
100.string.split (delimiter) returns an array of stored values.
101.string.substr (Start[,length]) takes a string from the first to the specified length.
102.string.tolowercase () turns the string all lowercase.
103.string.touppercase () makes all characters uppercase.
104.parseInt (String[,radix (on behalf of)]) is cast to an integral type.
105.parseFloat (String[,radix]) cast to floating-point type.
106.isNaN (variable): The test is a numeric type.
107. Define a constant keyword: const, the keyword that defines the variable: var
--------------------------------------------------------------------------------------------------------------- -----------------
Javascript38 kind of small tricks, recommended for beginners to view.
Event Source Object
Event.srcElement.tagName
Event.srcElement.type
Capture release
Event.srcElement.setCapture ();
Event.srcElement.releaseCapture ();
Event keys
Event.keycode
Event.shiftkey
Event.altkey
Event.ctrlkey
Event return value
Event.returnvalue
Mouse position
Event.x
Event.y
Form activity elements
Document.activeelement
Binding events
Document.captureevents (Event.keydown);
accessing form elements
document.all ("TXT"). focus ();
document.all ("TXT"). Select ();
Form commands
Document.execcommand
form cookies
Document.cookie
Menu Events
Document.oncontextmenu
Creating elements
Document.createelement ("SPAN");
Get elements based on mouse:
Document.elementfrompoint (EVENT.X,EVENT.Y). tagname== "TD
Document.elementfrompoint (EVENT.X,EVENT.Y). appendchild (MS)
Form picture
document.images[Index]
Form Event Bindings
Document.onmousedown=scrollwindow;
Elements
Document. form. elements[Index]
Object Binding Events
Document.all.xxx.detachEvent (' onclick ', a);
Number of plugins
Navigator.plugins
Take variable type
typeof ($js _libpath) = = "Undefined"
drop-down box
drop-down box. options[Index]
drop-down box. Options.length
Find objects
Document.getelementsbyname ("R1");
document.getElementById (ID);
Timing
Timer=setinterval (' ScrollWindow () ', delay);
Clearinterval (timer);
Uncode encoding
Escape (), unescape
Parent object
Obj.parentelement (DHTML)
Obj.parentnode (DOM)
The row of the interchange table
Tableid.moverow (2,1) document.all.csss.href = "A.css";
Replace CSS

Display Side-by
Display:inline
Hide Focus
Hidefocus=true
Line wrapping based on width
Style= "Word-break:break-all"
Auto Refresh
<meta http-equiv= "Refresh" content= "8; Url=http://c98.yeah.net ">
Simple Mail
<a href= "Mailto:[email protected]?subject=ccc&body=xxxyyy" >
Quick go to location
Obj.scrollintoview (True)
Anchor
<a name= "First" >
<a href= "#first" >anchors</a>
Web page Pass Parameters
Location.search ();
Can be edited
Obj.contenteditable=true
Execute menu command
Obj.execcommand
Double-byte characters
/[^/x00-/xff]/
Chinese characters
/[/u4e00-/u9fa5]/
Let the English string wrap beyond the table width
Word-wrap:break-word; Word-break:break-all;
Transparent background
<iframe src= "1.htm" width=300 height=180 allowtransparency></iframe>
Get style Content
Obj.style.cssText
HTML tags
Document.documentElement.innerHTML
First Style label
Document.stylesheets[0]
The first style in a style tag
Document.stylesheets[0].rules[0]
When you prevent clicking on an empty link, the page is often reset to the top end of the page.
<a href= "javascript:function ()" >word</a>
Previous page Source
Asp:
Request.ServerVariables ("Http_referer")
Javascript:
Document.referrer
Freeing memory
CollectGarbage ();
Disable Right-click
Document.oncontextmenu = function () {return false;}
Prohibit save
<noscript><iframe src= "*.htm" ></iframe></noscript>
Disable selection of <body oncontextmenu= "return false" ondragstart= "return false" Onselectstart = "return false" onselect= " Document.selection.empty () "oncopy=" Document.selection.empty () "onbeforecopy=" return false "onmouseup=" Document.selection.empty () >
Prohibit paste
<input Type=text onpaste= "return false" >
Address bar icon
<link rel= "Shortcut Icon" href= "Favicon.ico" >
Favicon.ico name Best not change 16*16 16 colors, put the virtual directory under the root directory
Favorites Bar Icons
<link rel= "Bookmark" href= "Favicon.ico" >
View Source
<input type=button value= View Web page source code onclick= "window.location = ' view-source: ' + 'http://www.csdn.net/' >
Turn off IME
<input style= "ime-mode:disabled" >
Auto Select All
<input type=text name=text1 value= "123" onfocus= "This.select ()" >
Enter key to move the cursor to the next input box
<input onkeydown= "if (event.keycode==13) event.keycode=9" >
Default values for text boxes
<input type=text value= "123" onfocus= "alert (this.defaultvalue)" >
Title Line break
Obj.title = "123 SDFs"
Get the microsecond that time represents
var n1 = new Date ("2004-10-10". Replace (/-/g, "//")). GetTime ()
Whether the window is closed
Win.closed
CheckBox flat
<input type=checkbox style= "Position:absolute; Clip:rect (5px 15px 15px 5px) "><br>
Get selection
Document.selection.createRange (). Duplicate (). Text
Auto-complete function
<input type=text autocomplete=on> turn on this feature
<input type=text autocomplete=off> Turn off this feature
Window maximization
<body onload= "Window.resizeto (window.screen.width-4,window.screen.height-50); Window.moveTo ( -4,-4)" >
No Close button IE
window.open ("aa.htm", "Meizz", "fullscreen=7");
Unified encoding/decoding
Alert (decodeURIComponent (encodeURIComponent ("/ httpHello. com?as= hehe ")))
encodeURIComponent to ":", "/", ";" and "?" also coded
Table row Indication
<tr onmouseover= "this.bgcolor= ' #f0f0f0 '" onmouseout= "this.bgcolor= ' #ffffff '" >

JavaScript Tips-js Tips collection (RPM)

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.