Some JavaScript tips collected!
Event source object
Event.srcelement.tagname
Event.srcelement.Type
Capture release
Event.srcelement.setcapture ();
Event.srcelement.releasecapture ();
Event button
Event.Keycode
Event.shiftKey
Event.altKey
Event.ctrlKey
Event return value
Event.ReturnValue
Mouse location
Event.x
Event.y
Form activity element
Document.ActiveElement
Binding event
Document.captureEvents (Event.KeyDown);
Access form elements
Document.all ("txt"). FOCUS ();
Document.all ("txt"). SELECT ();
Form command
Document.execcommand
Form cookie
Document.cookie
Menu event
Document.onContextMenu
Create an element
Document.createElement ("span");
Element according to the mouse:
Document.ementFromPoint (event.x, time.y) .tagname == "TD
Document.ementFromPoint (Event.x, Event.y) .appendchild (ms)
Form image
Document.Images [index]
Form event binding
Document.οnmοusedοwn = scrollwindow;
element
Document. Form. Elements [index]
Object binding event
Document.all.xxx.detachevent ('Onclick', A);
Plugin number
Navigator.plugins
Variable type
TypeOf ($ JS_LIBPATH) == "undefined"
Pull down box
Drop the box .options [index]
Drop the box .options.Length
Find object
Document.getlementsByname ("R1");
Document.getlementByID (ID);
timing
Timer = setInterval ('scrollwindow ()', delay);
ClearInterval (Timer);
UNCODE encoding
Escape (), unescape
Parent
Obj.parentelement (DHTML)
Obj.parentNode (DOM)
Exchange table
TableID.MOVEROW (2, 1)
Replace CSS
Document.all.css.href = "a.css";
Parallel display
Display: inline
Hidden focus
Hidefocus = true
Wrap according to the width
Style = "Word-Break: Break-all"
Auto Refresh
Simple mail
Quick transfer to position
Obj.Scrollintoview (True)
anchor
Anchors web page delivery parameters
Location.Search ();
editable
Obj.conteTedITable = true
Execute a menu command
Obj.execcommand
Double-character character
/ [^ / X00- / XFF] /
Chinese character
/ [/ u4e00- / u9fa5] /
Let the English string exceed the table width automatic wrap
Word-Wrap: Break-Word; Word-Break: Break-all;
Transparent Background
Get STYLE content
Obj.style.csstext
HTML tag
Document.documentelement.innerhtml
First style tag
Document.Stylesheets [0]
The first style in the style tag
Document.stylesheets [0] .Rules [0]
When you prevent clicking on an empty link, the page is often reset to the top of the page.
Previous web source
ASP:
Request.ServerVariables ("http_referer")
JavaScript:
Document.referrer
Release memory
Collectgarbage ();
No right click
Document.onContextMenu = function () {Return False;}
Prohibit preservation
Prohibit selection
Prohibiting paste
Address bar icon
Favicon.ico name is preferably 16 * 16 16 colors, put the virtual catalog root directory
Collection icon
View source code
>
Close input method
Automatic selection
Enter key to move the cursor to the next input box
The default value of the text box
Title wrap
Obj.title = "123 & # 13sdfs & # 32"
Get the microseconds represented by time
VAR N1 = New Date ("2004-10-10" .Replace (/ - / g, "//")). gettime ()
Whether the window is closed
Win.Closed
Checkbox flat
Unrelated button IE
WINDOW.OPEN ("aa.htm", "meizz", "fullscreen = 7");
Unified encoding / decoding
Alert (encodeuricomponent ("http:// Hello .com? as = hehe")))))))
Encodeuricomponent pairs ":", "/", ";" also encoded
Table line instruction
// Various sizes
S = "/ R / N web page visible area width:" Document.body.clientwidth;
S = "/ R / N web page visible area is high:" Document.body.clientHEIGHT;
S = "/ r / n web page visible area high:" Document.Body.offSetWeight "(including the width of the edge);
S = "/ R / N web page visible area high:" Document.Body.OffsetHeight "(including the width of the edge);
S = "/ r / N web page text full text:" Document.body.scrollwidth; s = "/ r / N web page text full text:" Document.body.scrollHeight;
S = "/ R / N web page is rolled with high:" Document.body.scrolltop;
S = "/ r / n web page is rolled away:" Document.Body.Scrollleft;
S = "/ R / N web page text section:" WINDOW.SCREENTOP;
S = "/ R / N web page body part left:" window.screenleft;
S = "/ R / N screen resolution is high:" window.screen.height;
S = "/ R / N screen resolution width:" window.screen.width;
S = "/ R / N screen available workspace height:" window.screen.availheight;
S = "/ R / N screen available work area width:" window.screen.availwidth;
// Filter number
= 48 && event.keycode <= 57 || (this.Value.indexof (') <0? Event.KeyCode == 46: false)" οnpaste = "Return CLIPBOARDDATA.GETDATA ('Text'). match (// d /) ndragenter = "Return False">
[Ctrl A All Select Tips: You can modify some code first, press Run]
//Special Purpose
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
[Ctrl A All Select Tips: You can modify some code first, press Run]
// does not cache
// Regular match
Regular expressions matching Chinese characters: [/ u4e00- / u9fa5]
Match double-byte characters (including Chinese characters): [^ / X00- / XFF]
Regular expression of matching blank line: / n [/ s |] * / r
Matching the regular expression of HTML tag: / <(. *)>. * // 1> | <(. *) //> /
Regular expression of matching the first tail space: (^ / s *) | (/ s * $) (/ s * $) (like Vbscript Trim function)
Match the regular expression of the email address: / w ([- .] / W ) * @ / w ([-.] / W ) * /. / W ([-.] / W ) *
Matching URL URL regular expressions: http: // ([/ w-] /.) [/ W-] (/ [/ w- ./?%&=]*)?
The following is examples:
Use the regular expression to limit the text box in the text box in the web form:
Use the regular expression restrictions can only be entered in Chinese: οNKEYUP = "value = value.replace (/ [^ / U4E00- / U9FA5] / g, '')" onbeforepaste = "ClipboardData.SetData ('Text', ClipboardData.Getdata) 'Text'). Replace (/ [^ / U4E00- / U9FA5] / g, '')) "
1. Use the regular expression to limit only full-corner character: οnkeyup = "value = value.replace (/ [^ / uff00- / ufff] / g, ')" onbeforepaste = "ClipboardData.SetData (' Text ', ClipboardData) .getdata ('text'). Replace (/ [^ / UFF00- / UFFFFFFF] / g, ')) "
2. Use the regular expression to limit only numbers: οnkeyup = "value = value.replace (/ [^ / d] / g, '')" onbeforepaste = "ClipboardData.SetData ('Text', ClipboardData.Getdata) Text '). Replace (/ [^ / d] / g,' ') "3. Use the regular expression limit to enter only numbers and English: οnkeyup =" value = value.replace (/ [/ w] / g , '') "Onbeforepaste =" ClipboardData.SetData ('Text', ClipboardData.Getdata ('Text'). Replace (/ [^ / D] / g, '') ")
// Eliminate image toolbar
oral
hEAD>
[Ctrl A All Select Tips: You can modify some code first, press Run]
// No prompt to close
Function close ()
{
Var ua = navigator.USERAGENT
Var ie = navigator.appname == "Microsoft Internet Explorer"? True: false
IF (IE)
{
Var ieversion = parsefloat (u.indexof ("msie") 5, ua.indexof (";", ua.indexof ("msie")))))))))
Ieversion <5.5)
{
Var str = '
Str = ' Object>';
Document.body.insertadjacenthtml ("BeForend", STR);
Document.All.notipclose.click ();
}
Else
{
WINDOW.OPENER = NULL;
WINDOW.CLOSE ();
}
}
Else
{
WINDOW.CLOSE ()
}
}
/ / Get an absolute position of the control (1)
Function Getoffset (e)
{
VAR T = E.OffSettop;
Var L = E.Offsetleft;
While (E = E.OffSetParent)
{
T = E.OffSettop;
L = E.Offsetleft;
}
Var REC = New Array (1);
REC [0] = T; REC [1] = L;
Return REC
}
script>
[Ctrl A All Select Tips: You can modify some code first, press Run]
/ / Get absolute position of the control (2)
ORECT = Obj.getBoundingClientRect ();
ORECT.LEFT
ORECT.
// Minimize, maximize, close
object>
object>
Object>
[Ctrl A All Select Tips: You can modify some code first, press Run]
/ / The cursor stops in the text
Function CC ()
{
Var e = esent.srcelement;
Var r = E.CREATETEXTRANGE ();
R.MoveStart ('Character', E.Value.Length);
R.Collapse (True);
R.select ();
}
script>
[Ctrl A All Select Tips: You can modify some code first, press Run]
// Special effects entering and exiting page
Go to page ">
Launch page
There are some of the attribute values:
The attribute value is "all": the file will be retrieved, and the page will be queried;
The attribute value is "none": the file is not retrieved, and the link on the page is not queried;
The attribute value is "index": the file will be retrieved;
The attribute value is "FOLLOW": the link on the query page;
The attribute value is "noIndex": the file is not retrieved, but can be queried by the query;
The attribute value is "nofollow":
// Print Page
Page2 p>
[Ctrl A All Select Tips: You can modify some code first, press Run]
// Setup print
p>
center>
/ / Take the header footage when printing
Var HKEY_ROOT, HKEY_PATH, HKEY_KEY;
HKEY_ROOT = "HKEY_CURRENT_USER";
HKEY_PATH = "// Software // Microsoft // Internet Explorer // Pagesetup //";
/ / Set the page foot foot of the web page
Function Pagesetup_null ()
{
Try
{
Var wsh = new activXObject ("wscript.shell");
HKEY_KEY = "HEADER";
Wsh.regWrite (HKEY_ROOT HKEY_PATH HKEY_KEY, "");
HKEY_KEY = "Footer";
Wsh.regWrite (HKEY_ROOT HKEY_PATH HKEY_KEY, "");
}
Catch (e) {}
}
/ / Set the page foot foot of the web page as the default value
Function Pagesetup_default ()
{
Try
{
Var wsh = new activXObject ("wscript.shell");
HKEY_KEY = "HEADER";
Wsh.Regwrite (HKEY_ROOT HKEY_PATH HKEY_KEY, "& W & W & P";
HKEY_KEY = "Footer";
Wsh.Regwrite (HKEY_ROOT HKEY_PATH HKEY_KEY, "& U & B & D");
}
Catch (e) {}
}
script>
[Ctrl A All Select Tips: You can modify some code first, press Run]
// Browser verification
Function checkbrowser ()
{
THIS.VER = Navigator.AppVersion
this.dom = Document.getElementByid? 1: 0
THIS.IE6 = (THISTER.INDEXOF ("MSIE 6")> - 1 && this.dom)? 1: 0;
THIS.IE5 = (THISTER.INDEXOF ("MSIE 5")> - 1 && this.dom)? 1: 0; this.ie4 = (Document.all &&! this.dom)? 1: 0;
THIS.NS5 = (this.dom && parseint (this.ver)> = 5)? 1: 0;
THIS.NS4 = (Document.Layers &&! this.dom)? 1: 0;
THIS.MAC = (this.ver.indexof ('mac')> -1)? 1: 0;
THIS.OPE = (Navigator.UserageRagent.indexof ('Opera')> - 1);
THIS.IE = (this.ie6 || this.ie5 || this.ie4)
THIS.NS = (this.ns4 || this.ns5)
THIS.BW = (this.ie6 || this.ie5 || this.ie4 || this.ns5 || this.ns4 || this.mac || this.ope)
THIS.NBW = (! this.bw)
Return this;
}
/ / Calculate content and high
Function Test (OBJ)
{
Var Range = Obj.createTextRange ();
Alert ("Content Area Width:" Range.BoundingWidth
"PX / R / N content area height:" Range.BoundingHeight "PX");
}
Script>