Common JavaScript skills in the Web (1)

Source: Internet
Author: User
Tags tagname
Event source object


Event. srcelement. tagname
Event. srcelement. Type

Capture and release

Event. srcelement. setcapture ();
Event. srcelement. releasecapture ();

Event buttons


Event. keycode
Event. shiftkey
Event. altkey
Event. ctrlkey

Event Return Value


Event. returnvalue

Mouse position

Event. x
Event. Y

Form Activity element


Document. activeelement

Bind event


Document. captureevents (event. keydown );

Access form elements

Document. All ("TXT"). Focus ();
Document. All ("TXT"). Select ();

Form commands

Document.exe ccommand

Form cookie

Document. Cookie

Menu events

Document. oncontextmenu


Create Element

Document. createelement ("span ");

Obtain the element with the mouse:


Document. elementfrompoint (event. X, event. Y). tagname = "TD
Document. elementfrompoint (event. X, event. Y). appendchild (MS)

Form Image


Document. Images [Index]

Form event binding

Document. onmousedown = scrollwindow;

Element

Document. Form. elements [Index]

Object binding event

Number of plug-ins


Navigator. plugins

Variable type


Typeof ($ js_libpath) = "undefined"

Drop-down list


Drop-down box. Options [Index]
Drop-down box. Options. Length

Search for objects

Document. getelementsbyname ("R1 ");
Document. getelementbyidx (ID );

Timing

Uncode Encoding

Escape (), Unescape

Parent object

OBJ. parentelement (DHTML)
OBJ. parentnode (DOM)

Exchange table rows


Tableid. moverow (2, 1)

Replace CSS

Document.all.css S. href = "a.css ";

Side by side

Display: inline


Hide focus

Hidefocus = true

Line feed Based on Width


Style = "word-break: Break-all"


Auto refresh

<Meta HTTP-EQUIV = "***" content = "8; url = http://c98.yeah.net">


Simple email


<A href = "mailto: aaa@bbb.com? Subject = CCC & Body = xxxyyy ">

Quickly go to location

OBJ. scrollintoview (true)


Anchor


<A name = "first">
<A href = "# First"> anchors </a>

Webpage Transfer Parameters


Location. Search ();

Editable


OBJ. contenteditable = true

Run the menu command


Obj.exe ccommand

Double-byte characters

/[^ \ X00-\ xFF]/

Chinese characters

/[\ U4e00-\ u9fa5]/

Automatically wrap an English string out of the table width


Word-wrap: Break-word; Word-break: Break-all;

Transparent background


<IFRAME src = "http://www.blog.com.cn/1.htm" width = 300 Height = 180 allowtransparency> </iframe>

Get style content


Obj.style.css text

HTML Tag


Document.doc umentelement. innerhtml

First style label


Document. stylesheets [0]

The first style in the style label


Document. stylesheets [0]. Rules [0]

When you click an empty link, the page is often reset to the top.


<A href = "javascript: function ()"> word </a>

Previous webpage Source


ASP:
Request. servervariables ("http_referer ")
Javascript:
Document. referrer

Release memory


Collectgarbage ();

Disable right-click

Document. oncontextmenu = function () {return false ;}

Save prohibited

<NoScript> <IFRAME src = "http://www.blog.com.cn/developer.htm"> </iframe> </NoScript>

Deselected

<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 ()>

Disable pasting


<Input type = text onpaste = "Return false">

Address bar icon

<LINK rel = "shortcut icon" href = "favicon. ICO">

It is recommended that the favicon. ICO name remain the same as 16 colors for 16*16. Put it in the root directory of the virtual directory.
Add to favorites bar icon

<LINK rel = "bookmark" href = "favicon. ICO">

View Source Code

Disable Input Method


<Input style = "ime-mode: Disabled">

Automatically select all


<Input type = text name = text1 value = "http://www.blog.com.cn/123" onfocus = "This. Select ()">

Enter to move the cursor to the next input box


<Input onkeydown = "If (event. keycode = 13) event. keycode = 9">

Default Value of the text box


<Input type = text value = "http://www.blog.com.cn/123" onfocus = "alert (this. defaultvalue)">

Title line feed


OBJ. Title = "123 & #13 sdfs & #32"

Obtain the microseconds represented by the time

VaR n1 = new date ("2004-10-10". Replace (/-/g, "\/"). gettime ()

Close Window?

Win. Closed

Checkbox flat


<Input type = checkbox style = "position: absolute; clip: rect (5px 15px 15px 5px)">

Obtain selected content

Document. selection. createRange (). Duplicate (). Text

Automatic completion


<Input type = text AutoComplete = on> enable this function
<Input type = text AutoComplete = off> disable this function.

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 ("http: // hello. com? As = hehe ")))
Encodeuricomponent for ":", "/", ";" and "? "Also Encoding

Table row indication

// Various dimensions

S + = "\ r \ n visible area width of the webpage:" + document. Body. clientwidth;
S + = "\ r \ n visible area of the webpage:" + document. Body. clientheight;
S + = "\ r \ n visible area of the webpage Height:" + document. Body. offsetweight + "(including the width of the edge )";
S + = "\ r \ n visible area height of the webpage:" + document. Body. offsetheight + "(including the width of the edge )";
S + = "\ r \ n webpage body full text width:" + document. Body. scrollwidth;
S + = "\ r \ n webpage text Height:" + document. Body. scrollheight;
S + = "\ r \ n webpage volume Height:" + document. Body. scrolltop;
S + = "\ r \ n left when the webpage is rolled:" + document. Body. scrollleft;
S + = "\ r \ n webpage body part:" + window. screentop;
S + = "\ r \ n left part of the webpage body:" + window. screenleft;
S + = "\ r \ n screen resolution Height:" + window. Screen. height;
S + = "\ r \ n screen resolution width:" + window. Screen. width;
S + = "\ r \ n available workspace Height:" + window. Screen. availheight;
S + = "\ r \ n available workspace width of the screen:" + window. Screen. availwidth;
// No Cache

<Meta HTTP-EQUIV = "Pragma" content = "no-Cache">
<Meta HTTP-EQUIV = "cache-control" content = "no-cache, must-revalidate">
<Meta HTTP-EQUIV = "expires" content = "0">

// Regular Expression matching

Regular Expression matching Chinese characters: [\ u4e00-\ u9fa5]
Match double-byte characters (including Chinese characters): [^ \ x00-\ xFF]
Regular Expression for matching empty rows: \ n [\ s |] * \ r
Regular Expressions matching HTML tags:/<(. *)>. * <\/\ 1> | <(. *) \/>/
Regular Expressions matching spaces at the beginning and end: (^ \ s *) | (\ s * $) (TRIM functions like VBScript)
The regular expression matching the email address: \ W + ([-+.] \ W +) * @ \ W + ([-.] \ W + )*\. \ W + ([-.] \ W + )*
The regular expression matching the URL: http: // ([\ W-] + \.) + [\ W-] + (/[\ W -./? % & =] *)?

Example: # JavaScript/ajax Column

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.