javascript

语法基础

 

javascript与java语法相似。

 

注释 ://,/* */。 

标识符 (变量名、函数名、标签名): 字母 、 数字 、 _ 、和 $ 的组合,数字不能开头。

关键字 :break、case、catch、continue、default、delete、do、else、false、finally、for、function、if、in、instanceof、new、null、return、switch、this、throw、true、try、typeof、var、void、while、with

预留关键字 :abstract、boolean、byte、char、class、const、debugger、double、enum、export、extends、final、float、goto、implements、import、int、interface、long、native、package、private、protected、public、short、static、super、synchronized、throws、transient、volatile

变量 :var i=1+2+3; // var x=3, message="ok"。变量无类型,可以包含任何数据类型的值;声明在函数外的 全局变量 对整个javascript程序可见,声明在函数内的 局部变量 只在函数域内可见。javascript没有块级域的概念:定义在花括号里的变量在外部仍可见。

数据类型 : 数字 (1、3.14、0xFF,用isNaN函数测试一个值不是数字); 布尔(true、false); 字符串 ('hello'、"OK"、'and "nested" ',16位unicode字符集);对象 (var o = new Object()、var o={x:1, y:2, z:3}、o.x=1、o["x"]=1); 数组 (var a = new Array()、var a = new Array(1,2,3)、var a = [1, 2, 3]、var b = [1, true, [1,2], {x:1,y:2}, "OK"]、a[1]=a[0]+a[2])

函数 :function sum(x,y) { return x + y; };var sum = new Function("x", "y", "return x+y;");;var sum = function(x,y) { return x+y; };var total = sum(1,2);。

空值和未定义值 :null表示空值;undefined表示未定义值;两者“==”结果为true,但“===”结果为false。

操作符 :与java基本相同,.、[]、()、new、++、--、-、+、~、!、delete、typeof、void、*、/、%、<<、>>、>>>、<、<=、>、>=、instanceof、in、==、!=、===、!==、&、^、|、&&、||、?:、,、=、*=、+=、-=、等等。“==”表示松散相等,允许类型转换,比如3=="3"为真;“===”为严格相等,必须有相同类型且值相等。比较符作用在字符串上时基于字母序。“in”表示右边的对象是否继承或包含左边的对象。

语句 :表达式;、{表达式1; 表达式2}、空语句;、label: statement;break [label]、case、continue [label]、default、do/while、for、for/in、function、if/else、return、switch、throw、try/catch/finally、var、while、with。

面向对象 :

function Point(x,y) { //constructor

  this.x = x;

  this.y = y;

  this.f = function() { return x + y; }

}

Point.static_member = 5; // 静态变量

Point.static_function = function { return static_member; } // 静态方法

 

正则表达式 :支持的特殊字符有:[...]、[^...]、\w、\W、\s、\S、\d、\D、?、+、*、{n}、{n,}、{n,m}、a|b、(sub)、(?:sub)、\n、$n、^、$、\b、\B、(?=p)、(?!p)。其中(?:sub)表示不存储匹配的值到变量;\n表示匹配第n组的子表达式;$n表示替换第n组的子表达式;(?=p)前瞻匹配;(?!p)前瞻否定匹配。

 

客户端javascript

客户端javascript是嵌入到HTML里由浏览器执行的javascript代码。HTML里用<script>标签来定义脚本语言。HTML控件可以使用event handler来调用javascript的代码,比如<input type="button" οnclick="alert ('OK')">。也可以在表单的提交动作里执行javascript,比如<form action="javascript:alert('OK')">。

 

Window对象 表示一个浏览器窗口,它是全局对象,定义所有顶层属性和方法。通过window可以得到这个全局对象,从而可以访问它的属性和方法,比如window.document。通常这个window.前缀可以省略,比如我们可以直接使用document。

 

简单的对话框 有 alert 、 confirm 、和 prompt 。例如:

alert("Hello");

if (confirm("OK?")) {

    var name = prompt("input your name");

}

 

状态栏 :浏览器下方会有状态栏,用 window.status 来访问,比如status="OK"。很多浏览器出于安全考虑,已经禁用了这个功能。

 

计时器 :var timer = setTimeout ("document.title=++count", 1000);设置一个1秒后执行的计时器; clearTimeout (timer)可以清除这个计时器。对应的, setInterval 和clearInterval 用来设置和清除循环的计时器。

 

系统信息 :Window对象的navigator和screen属性分别对应于浏览器和屏幕对象,通过它们我们可以得到浏览器的名字和版本信息、操作系统、用户屏幕的分辨率等。

 

浏览器 :Window对象的 location 属性指向浏览器的地址栏内容,我们可以读取它,甚至设置成一个新的网址,比如location="http://localhost"。虽然location表现得像一个字符串一样,但它其实是一个Location对象。Window对象的 history 属性表示浏览器的历史记录,可以用history.back()和history.forward()来后退和前进,history.go(-3)后退三次。 

 

Window控制 :Window对象提供了移动(moveTo、moveBy)、改变大小(resizeTo、resizeBy)、滚动窗口(scrollTo、ScrollBy)、得到焦点(focus)、放弃焦点(blur)的方法。更重要的一个方法是open,它可以打开一个新的窗口,例:var w = open("url.html", "window name", "resizable");,其中第二个参数是窗口名,如果已经存在则重用这个窗口;第三个参数是特性,可以设置新窗口的宽度、高度等。调用w.close()可以关闭这个窗口。

 

Document对象 :每个Window对象都有一个document属性来表示当前文档,它比Window对象本身更有重要。文档内容被访问和修改的方式被称为DOM(Document Object Model)。DOM对应于文档元素的树形结构。

 

W3C DOM :包括三个部分:core DOM(适用于任何结构体文档)、 XML DOM和HTML DOM 。HTML DOM是增加、修改、删除和访问HTML元素的标准。 document. getElementById和 document.getElementsByTagName用来得到元素节点。注意,getElementsByTagName会返回一个数组,可以用[]下标符来得到其中的元素。 有两个特殊的节点:document. documentElement和 document.body,可以直接访问。得到的每个节点都为一个Node对象。

 

HTML DOM Node :三个重要的属性: nodeName(大写的元素标签名)、 nodeValue(标签包含的文本)、 nodeType(如下)。

Element typeNodeType
Element1
Attribute2
Text3
Comment8
Document9

 

改变HTML :例: < button onclick = "document.getElementsByTagName('title')[0].innerHTML='New Tile'" >。

 

Cookie :通过document.cookie可以访问和设置与网页相关的cookie。比如document.cookie="key=value; expires=date; path=xxx";,多次调用可以加入多个cookie。expires指定过期时间,如果不设置那么cookie在网页关闭后失效;设置path属性可以使cookie在多个网页内共享。在读取cookie时,会返回以“, ”分隔的字符串,每个语素都是“key=value”的形式,注意expires和path不会显示在返回值里。

 

DHTML :这不是一门语言,而是一个术语。Dynamic HTML,表示通过 HTML、 JavaScript、 HTML DOM、 和CSS 达到动态生成HTML效果。

 

javascript对象

Array

 

 

PropertyDescription
constructorReturns the function that created the Array object's prototype
lengthSets or returns the number of elements in an array
prototypeAllows you to add properties and methods to an Array object
MethodDescription
concat()Joins two or more arrays, and returns a copy of the joined arrays
indexOf()Search the array for an element and returns it's position
join()Joins all elements of an array into a string
lastIndexOf()Search the array for an element, starting at the end, and returns it's position
pop()Removes the last element of an array, and returns that element
push()Adds new elements to the end of an array, and returns the new length
reverse()Reverses the order of the elements in an array
shift()Removes the first element of an array, and returns that element
slice()Selects a part of an array, and returns the new array
sort()Sorts the elements of an array
splice()Adds/Removes elements from an array
toString()Converts an array to a string, and returns the result
unshift()Adds new elements to the beginning of an array, and returns the new length
valueOf()Returns the primitive value of an array

 

Boolean

PropertyDescription
constructorReturns the function that created the Boolean object's prototype
prototypeAllows you to add properties and methods to a Boolean object
MethodDescription
toString()Converts a Boolean value to a string, and returns the result
valueOf()Returns the primitive value of a Boolean object

Date

var d = new Date(); 
var d = new Date(  milliseconds  ); 
var d = new Date(  dateString  ); 
var d = new Date(  year    month    day    hours    minutes    seconds    milliseconds  ); 
 
PropertyDescription
constructorReturns the function that created the Date object's prototype
prototypeAllows you to add properties and methods to an object
MethodDescription
getDate()Returns the day of the month (from 1-31)
getDay()Returns the day of the week (from 0-6)
getFullYear()Returns the year (four digits)
getHours()Returns the hour (from 0-23)
getMilliseconds()Returns the milliseconds (from 0-999)
getMinutes()Returns the minutes (from 0-59)
getMonth()Returns the month (from 0-11)
getSeconds()Returns the seconds (from 0-59)
getTime()Returns the number of milliseconds since midnight Jan 1, 1970
getTimezoneOffset()Returns the time difference between GMT and local time, in minutes
getUTCDate()Returns the day of the month, according to universal time (from 1-31)
getUTCDay()Returns the day of the week, according to universal time (from 0-6)
getUTCFullYear()Returns the year, according to universal time (four digits)
getUTCHours()Returns the hour, according to universal time (from 0-23)
getUTCMilliseconds()Returns the milliseconds, according to universal time (from 0-999)
getUTCMinutes()Returns the minutes, according to universal time (from 0-59)
getUTCMonth()Returns the month, according to universal time (from 0-11)
getUTCSeconds()Returns the seconds, according to universal time (from 0-59)
getYear() Deprecated.  Use the getFullYear() method instead
parse()Parses a date string and returns the number of milliseconds since midnight of January 1, 1970
setDate()Sets the day of the month of a date object
setFullYear()Sets the year (four digits) of a date object
setHours()Sets the hour of a date object
setMilliseconds()Sets the milliseconds of a date object
setMinutes()Set the minutes of a date object
setMonth()Sets the month of a date object
setSeconds()Sets the seconds of a date object
setTime()Sets a date and time by adding or subtracting a specified number of milliseconds to/from midnight January 1, 1970
setUTCDate()Sets the day of the month of a date object, according to universal time
setUTCFullYear()Sets the year of a date object, according to universal time (four digits)
setUTCHours()Sets the hour of a date object, according to universal time
setUTCMilliseconds()Sets the milliseconds of a date object, according to universal time
setUTCMinutes()Set the minutes of a date object, according to universal time
setUTCMonth()Sets the month of a date object, according to universal time
setUTCSeconds()Set the seconds of a date object, according to universal time
setYear() Deprecated.  Use the setFullYear() method instead
toDateString()Converts the date portion of a Date object into a readable string
toGMTString() Deprecated.  Use the toUTCString() method instead
toISOString()Returns the date as a string, using the ISO standard
toJSON()Returns the date as a string, formated as a JSON date
toLocaleDateString()Returns the date portion of a Date object as a string, using locale conventions
toLocaleTimeString()Returns the time portion of a Date object as a string, using locale conventions
toLocaleString()Converts a Date object to a string, using locale conventions
toString()Converts a Date object to a string
toTimeString()Converts the time portion of a Date object to a string
toUTCString()Converts a Date object to a string, according to universal time
UTC()Returns the number of milliseconds in a date string since midnight of January 1, 1970, according to universal time
valueOf()Returns the primitive value of a Date object

Math

var x = Math.PI; // Returns PI 
var y = Math.sqrt(16); // Returns the square root of 16 
 
PropertyDescription
EReturns Euler's number (approx. 2.718)
LN2Returns the natural logarithm of 2 (approx. 0.693)
LN10Returns the natural logarithm of 10 (approx. 2.302)
LOG2EReturns the base-2 logarithm of E (approx. 1.442)
LOG10EReturns the base-10 logarithm of E (approx. 0.434)
PIReturns PI (approx. 3.14)
SQRT1_2Returns the square root of 1/2 (approx. 0.707)
SQRT2Returns the square root of 2 (approx. 1.414)
MethodDescription
abs(x)Returns the absolute value of x
acos(x)Returns the arccosine of x, in radians
asin(x)Returns the arcsine of x, in radians
atan(x)Returns the arctangent of x as a numeric value between -PI/2 and PI/2 radians
atan2(y,x)Returns the arctangent of the quotient of its arguments
ceil(x)Returns x, rounded upwards to the nearest integer
cos(x)Returns the cosine of x (x is in radians)
exp(x)Returns the value of E x
floor(x)Returns x, rounded downwards to the nearest integer
log(x)Returns the natural logarithm (base E) of x
max(x,y,z,...,n)Returns the number with the highest value
min(x,y,z,...,n)Returns the number with the lowest value
pow(x,y)Returns the value of x to the power of y
random()Returns a random number between 0 and 1
round(x)Rounds x to the nearest integer
sin(x)Returns the sine of x (x is in radians)
sqrt(x)Returns the square root of x
tan(x)Returns the tangent of an angle

Number

var num = new Number(value); 
 
PropertyDescription
constructorReturns the function that created the Number object's prototype
MAX_VALUEReturns the largest number possible in JavaScript
MIN_VALUEReturns the smallest number possible in JavaScript
NEGATIVE_INFINITYRepresents negative infinity (returned on overflow)
POSITIVE_INFINITYRepresents infinity (returned on overflow)
prototypeAllows you to add properties and methods to an object
MethodDescription
toExponential(x)Converts a number into an exponential notation
toFixed(x)Formats a number with x numbers of digits after the decimal point
toPrecision(x)Formats a number to x length
toString()Converts a Number object to a string
valueOf()Returns the primitive value of a Number object

String

var txt = new String("  string  "); 
var txt = "  string  "; 
 
PropertyDescription
constructorReturns the function that created the String object's prototype
lengthReturns the length of a string
prototypeAllows you to add properties and methods to an object
MethodDescription
charAt()Returns the character at the specified index
charCodeAt()Returns the Unicode of the character at the specified index
concat()Joins two or more strings, and returns a copy of the joined strings
fromCharCode()Converts Unicode values to characters
indexOf()Returns the position of the first found occurrence of a specified value in a string
lastIndexOf()Returns the position of the last found occurrence of a specified value in a string
match()Searches for a match between a regular expression and a string, and returns the matches
replace()Searches for a match between a substring (or regular expression) and a string, and replaces the matched substring with a new substring
search()Searches for a match between a regular expression and a string, and returns the position of the match
slice()Extracts a part of a string and returns a new string
split()Splits a string into an array of substrings
substr()Extracts the characters from a string, beginning at a specified start position, and through the specified number of character
substring()Extracts the characters from a string, between two specified indices
toLowerCase()Converts a string to lowercase letters
toUpperCase()Converts a string to uppercase letters
valueOf()Returns the primitive value of a String object
HTML Wrapper MethodDescription
anchor()Creates an anchor
big()Displays a string using a big font
blink()Displays a blinking string
bold()Displays a string in bold
fixed()Displays a string using a fixed-pitch font
fontcolor()Displays a string using a specified color
fontsize()Displays a string using a specified size
italics()Displays a string in italic
link()Displays a string as a hyperlink
small()Displays a string using a small font
strike()Displays a string with a strikethrough
sub()Displays a string as subscript text
sup()Displays a string as superscript text

RegExp

var patt=new RegExp(pattern,modifiers); 
var patt=/pattern/modifiers; 

ModifierDescription
iPerform case-insensitive matching
gPerform a global match (find all matches rather than stopping after the first match)
mPerform multiline matching
ExpressionDescription
[abc]Find any character between the brackets
[^abc]Find any character not between the brackets
[0-9]Find any digit from 0 to 9
[A-Z]Find any character from uppercase A to uppercase Z
[a-z]Find any character from lowercase a to lowercase z
[A-z]Find any character from uppercase A to lowercase z
[adgk]Find any character in the given set
[^adgk]Find any character outside the given set
(red|blue|green)Find any of the alternatives specified
MetacharacterDescription
.Find a single character, except newline or line terminator
\wFind a word character
\WFind a non-word character
\dFind a digit
\DFind a non-digit character
\sFind a whitespace character
\SFind a non-whitespace character
\bFind a match at the beginning/end of a word
\BFind a match not at the beginning/end of a word
\0Find a NUL character
\nFind a new line character
\fFind a form feed character
\rFind a carriage return character
\tFind a tab character
\vFind a vertical tab character
\xxxFind the character specified by an octal number xxx
\xddFind the character specified by a hexadecimal number dd
\uxxxxFind the Unicode character specified by a hexadecimal number xxxx
QuantifierDescription
n+Matches any string that contains at least one n
n*Matches any string that contains zero or more occurrences of n
n?Matches any string that contains zero or one occurrences of n
n{X}Matches any string that contains a sequence of  X n 's
n{X,Y}Matches any string that contains a sequence of X to Y  n 's
n{X,}Matches any string that contains a sequence of at least X  n 's
n$Matches any string with n at the end of it
^nMatches any string with n at the beginning of it
?=nMatches any string that is followed by a specific string n
?!nMatches any string that is not followed by a specific string n
PropertyDescription
globalSpecifies if the "g" modifier is set
ignorecaseSpecifies if the "i" modifier is set
lastIndexThe index at which to start the next match
multilineSpecifies if the "m" modifier is set
sourceThe text of the RegExp pattern
MethodDescription
compile()Compiles a regular expression
exec()Tests for a match in a string. Returns the first match
test()Tests for a match in a string. Returns true or false

 

Global

PropertyDescription
InfinityA numeric value that represents positive/negative infinity
NaN"Not-a-Number" value
undefinedIndicates that a variable has not been assigned a value
FunctionDescription
decodeURI()Decodes a URI
decodeURIComponent()Decodes a URI component
encodeURI()Encodes a URI
encodeURIComponent()Encodes a URI component
escape()Encodes a string
eval()Evaluates a string and executes it as if it was script code
isFinite()Determines whether a value is a finite, legal number
isNaN()Determines whether a value is an illegal number
Number()Converts an object's value to a number
parseFloat()Parses a string and returns a floating point number
parseInt()Parses a string and returns an integer
String()Converts an object's value to a string
unescape()Decodes an encoded string
 
Browser对象

Window

The window object represents an open window in a browser.

If a document contain frames (<frame> or <iframe> tags), the browser creates one window object for the HTML document, and one additional window object for each frame.

PropertyDescription
closedReturns a Boolean value indicating whether a window has been closed or not
defaultStatusSets or returns the default text in the statusbar of a window
documentReturns the Document object for the window (See Document object)
framesReturns an array of all the frames (including iframes) in the current window
historyReturns the History object for the window (See History object)
innerHeightSets or returns the inner height of a window's content area
innerWidthSets or returns the inner width of a window's content area
lengthReturns the number of frames (including iframes) in a window
locationReturns the Location object for the window (See Location object)
nameSets or returns the name of a window
navigatorReturns the Navigator object for the window (See Navigator object)
openerReturns a reference to the window that created the window
outerHeightSets or returns the outer height of a window, including toolbars/scrollbars
outerWidthSets or returns the outer width of a window, including toolbars/scrollbars
pageXOffsetReturns the pixels the current document has been scrolled (horizontally) from the upper left corner of the window
pageYOffsetReturns the pixels the current document has been scrolled (vertically) from the upper left corner of the window
parentReturns the parent window of the current window
screenReturns the Screen object for the window (See Screen object)
screenLeftReturns the x coordinate of the window relative to the screen
screenTopReturns the y coordinate of the window relative to the screen
screenXReturns the x coordinate of the window relative to the screen
screenYReturns the y coordinate of the window relative to the screen
selfReturns the current window
statusSets the text in the statusbar of a window
topReturns the topmost browser window
MethodDescription
alert()Displays an alert box with a message and an OK button
blur()Removes focus from the current window
clearInterval()Clears a timer set with setInterval()
clearTimeout()Clears a timer set with setTimeout()
close()Closes the current window
confirm()Displays a dialog box with a message and an OK and a Cancel button
createPopup()Creates a pop-up window
focus()Sets focus to the current window
moveBy()Moves a window relative to its current position
moveTo()Moves a window to the specified position
open()Opens a new browser window
print()Prints the content of the current window
prompt()Displays a dialog box that prompts the visitor for input
resizeBy()Resizes the window by the specified pixels
resizeTo()Resizes the window to the specified width and height
scroll() 
scrollBy()Scrolls the content by the specified number of pixels
scrollTo()Scrolls the content to the specified coordinates
setInterval()Calls a function or evaluates an expression at specified intervals (in milliseconds)
setTimeout()Calls a function or evaluates an expression after a specified number of milliseconds

Navigator

The navigator object contains information about the browser.

PropertyDescription
appCodeNameReturns the code name of the browser
appNameReturns the name of the browser
appVersionReturns the version information of the browser
cookieEnabledDetermines whether cookies are enabled in the browser
platformReturns for which platform the browser is compiled
userAgentReturns the user-agent header sent by the browser to the server
MethodDescription
javaEnabled()Specifies whether or not the browser has Java enabled
taintEnabled()Specifies whether or not the browser has data tainting enabled

Screen

The screen object contains information about the visitor's screen. 
PropertyDescription
availHeightReturns the height of the screen (excluding the Windows Taskbar)
availWidthReturns the width of the screen (excluding the Windows Taskbar)
colorDepthReturns the bit depth of the color palette for displaying images
heightReturns the total height of the screen
pixelDepthReturns the color resolution (in bits per pixel) of the screen
widthReturns the total width of the screen

History

The history object contains the URLs visited by the user (within a browser window).

The history object is part of the window object and is accessed through the window.history property.

PropertyDescription
lengthReturns the number of URLs in the history list
MethodDescription
back()Loads the previous URL in the history list
forward()Loads the next URL in the history list
go()Loads a specific URL from the history list

Location

The location object contains information about the current URL.

The location object is part of the window object and is accessed through the window.location property.

 
PropertyDescription
hashReturns the anchor portion of a URL
hostReturns the hostname and port of a URL
hostnameReturns the hostname of a URL
hrefReturns the entire URL
pathnameReturns the path name of a URL
portReturns the port number the server uses for a URL
protocolReturns the protocol of a URL
searchReturns the query portion of a URL
MethodDescription
assign()Loads a new document
reload()Reloads the current document
replace()Replaces the current document with a new one
 

 

Core DOM对象

 

Node

The Node object represents a node in the HTML document. 
PropertyDescriptionDOM
attributesReturns a collection of a node's attributes1
baseURIReturns the absolute base URI of a node3
childNodesReturns a NodeList of child nodes for a node1
firstChildReturns the first child of a node1
lastChildReturns the last child of a node1
localNameReturns the local part of the name of a node2
namespaceURIReturns the namespace URI of a node2
nextSiblingReturns the next node at the same node tree level1
nodeNameReturns the name of a node, depending on its type1
nodeTypeReturns the type of a node1
nodeValueSets or returns the value of a node, depending on its type1
ownerDocumentReturns the root element (document object) for a node2
parentNodeReturns the parent node of a node1
prefixSets or returns the namespace prefix of a node2
previousSiblingReturns the previous node at the same node tree level1
textContentSets or returns the textual content of a node and its descendants3
MethodDescriptionDOM
appendChild()Adds a new child node, to the specified node, as the last child node1
cloneNode()Clones a node1
compareDocumentPosition()Compares the document position of two nodes1
getFeature( feature , version )Returns a DOM object which implements the specialized APIs of the specified feature and version3
getUserData(key )Returns the object associated to a key on a this node. The object must first have been set to this node by calling setUserData with the same key3
hasAttributes()Returns true if a node has any attributes, otherwise it returns false2
hasChildNodes()Returns true if a node has any child nodes, otherwise it returns false1
insertBefore()Inserts a new child node before a specified, existing, child node1
isDefaultNamespace()Returns true if the specified namespaceURI is the default, otherwise false3
isEqualNode()Checks if two nodes are equal3
isSameNode()Checks if two nodes are the same node3
isSupported()Returns true if a specified feature is supported on a node, otherwise false2
lookupNamespaceURI()Returns the namespace URI matching a specified prefix3
lookupPrefix()Returns the prefix matching a specified namespace URI3
normalize()Joins adjacent text nodes and removes empty text nodes2
removeChild()Removes a child node1
replaceChild()Replaces a child node1
setUserData(key,data,handler)Associates an object to a key on a node3
Node typeDescriptionChildren
1ElementRepresents an elementElement, Text, Comment, ProcessingInstruction, CDATASection, EntityReference
2AttrRepresents an attributeText, EntityReference
3TextRepresents textual content in an element or attributeNone
4CDATASectionRepresents a CDATA section in a document (text that will NOT be parsed by a parser)None
5EntityReferenceRepresents an entity referenceElement, ProcessingInstruction, Comment, Text, CDATASection, EntityReference
6EntityRepresents an entityElement, ProcessingInstruction, Comment, Text, CDATASection, EntityReference
7ProcessingInstructionRepresents a processing instructionNone
8CommentRepresents a commentNone
9DocumentRepresents the entire document (the root-node of the DOM tree)Element, ProcessingInstruction, Comment, DocumentType
10DocumentTypeProvides an interface to the entities defined for the documentNone
11DocumentFragmentRepresents a "lightweight" Document object, which can hold a portion of a documentElement, ProcessingInstruction, Comment, Text, CDATASection, EntityReference
12NotationRepresents a notation declared in the DTDNone
Node typenodeName returnsnodeValue returns
1Elementelement namenull
2Attrattribute nameattribute value
3Text#textcontent of node
4CDATASection#cdata-sectioncontent of node
5EntityReferenceentity reference namenull
6Entityentity namenull
7ProcessingInstructiontargetcontent of node
8Comment#commentcomment text
9Document#documentnull
10DocumentTypedoctype namenull
11 DocumentFragment#document fragmentnull
12Notationnotation namenull
NodeTypeNamed Constant
1ELEMENT_NODE
2ATTRIBUTE_NODE
3TEXT_NODE
4CDATA_SECTION_NODE
5ENTITY_REFERENCE_NODE
6ENTITY_NODE
7PROCESSING_INSTRUCTION_NODE
8COMMENT_NODE
9DOCUMENT_NODE
10DOCUMENT_TYPE_NODE
11DOCUMENT_FRAGMENT_NODE
12NOTATION_NODE
 

NodeList  

The NodeList object represents an ordered collection of nodes.

The nodes in the NodeList can be accessed through their index number (starting from 0).

A NodeList object could be a Node's collection of child nodes.

PropertyDescriptionDOM
lengthReturns the number of nodes in the collection1
MethodDescriptionDOM
item()Returns the node at the specified index in a node list1

 

NamedNodeMap

The NamedNodeMap object represents an unordered collection of nodes.

The nodes in the NamedNodeMap can be accessed through their name.

A NamedNodeMap object could be a Node's collection of attributes.

PropertyDescriptionDOM
lengthReturns the number of nodes in the collection1
MethodDescriptionDOM
getNamedItem()Returns the specified node (by name)1
getNamedItemNS()Returns the specified node (by name and namespace)2
item()Returns the node at the specified index in the namedNodeMap1
removeNamedItem()Removes the specified node (by name)1
removeNamedItemNS()Removes the specified node (by name and namespace)2
setNamedItem()Sets the specified node (by name)1
setNamedItemNS()Sets the specified node (by name and namespace)2

 

Document

The Document object is the root of a document tree.

The Document object gives us access to the document's data.

Since element nodes, text nodes, attributes, comments, etc. cannot exist outside the document, the Document object contains methods to create these objects. All Node objects have a ownerDocument property which associates them with the Document where they were created.

 

PropertyDescriptionDOM
doctypeReturns the Document Type Declaration associated with the document1
documentElementReturns the Document Element of the document (the HTML element)1
documentURISets or returns the location of the document3
domConfigReturns the configuration used when normalizeDocument() is invoked3
implementationReturns the DOMImplementation object that handles this document1
inputEncodingReturns the encoding, character set, used for the document3
strictErrorCheckingSets or returns whether error-checking is enforced or not3
xmlEncodingReturns the XML encoding of the XML document3
xmlStandaloneSets or returns whether the XML document is standalone or not3
xmlVersionSets or returns the XML version of the XML document3
MethodDescriptionDOM
adoptNode(node)Adopts a node from another document to this document. Returns the adopted node3
createAttribute()Creates an attribute node1
createAttributeNS( URI , name )Creates an attribute with the specified name and namspaceURI2
createCDATASection()Creates a CDATA node with the specified text. For XML DOM only1
createComment()Creates a Comment node with the specified text1
createDocumentFragment()Creates an empty DocumentFragment node1
createElement()Creates an Element node1
createElementNS()Creates an element with the specified namespace2
createEntityReference()Creates an EntityReference node. For XML DOM only1
createProcessingInstruction()Creates an EntityReference node. For XML DOM only1
createTextNode()Creates a Text node1
getElementById()Returns the element that has the ID attribute with the specified value2
getElementsByTagName()Returns a NodeList containing all elements with the specified tagname1
getElementsByTagNameNS()Returns a NodeList containing all elements with the specified namespaceURI and tagname2
importNode()Imports a node from another document2
normalizeDocument()Removes empty Text nodes, and joins adjacent nodes3
renameNode()Renames the specified node3

 

Element

The Element object represents an element in the HTML document.

The Element object can have child nodes of type Element, Text, Comment, CDATASection, ProcessingInstruction, and EntityReference.

The Element object can have attributes, which have the node type Attr.

PropertyDescriptionDOM
schemaTypeInfoReturns the type information of the element.3
tagNameReturns the tag name of the element1
MethodDescriptionDOM
getAttribute()Returns the specified attribute value1
getAttributeNS()Returns the specified attribute value, with the specified namespace. For XML DOM only2
getAttributeNode()Returns the specified attribute node1
getAttributeNodeNS()Returns the specified attribute node, with the specified namespace. For XML DOM only3
getElementsByTagName()Returns a collection of all child elements with the specified tagname1
getElementsByTagNameNS()Returns a collection of all child elements with the specified tagname and namespace. For XML DOM only2
hasAttribute()Returns true if the element has the specified attribute, otherwise it returns false2
hasAttributeNS()Returns true if the element has the specified attribute, with the specified namespace, otherwise it returns false. For XML DOM only2
removeAttribute()Removes the specified attribute1
removeAttributeNS()Removes the attribute with the specified name and namespace. For XML DOM only2
removeAttributeNode()Removes the specified attribute node, and returns the removed node1
setAttribute()Sets or changes the specified attribute, to the specified value1
setAttributeNS()Sets or changes the specified attribute, with the specified namespace, to the specified value. For XML DOM only2
setAttributeNode()Sets or changes the specified attribute node1
setAttributeNodeNS()Sets or changes the specified attribute node2
setIdAttribute() 3
setIdAttributeNS() 3
setIdAttributeNode() 3

 

Attr

PropertyDescriptionDOM
isIdReturns  true  if the attribute is of type ID, otherwise it returns  false 3
nameReturns the name of the attribute1
ownerElementReturns the element this attribute belongs to2
schemaTypeInfoReturns the type information of the attribute3
specifiedReturns  true  if the attribute has been specified, otherwise it returns  false 1
valueSets or returns the value of the attribute1
 
 
HTML DOM基本对象
 

Document

PropertyDescriptionW3C
anchorsReturns a collection of all the anchors in the documentYes
appletsReturns a collection of all the applets in the documentYes
bodyReturns the body element of the documentYes
cookieReturns all name/value pairs of cookies in the documentYes
documentModeReturns the mode used by the browser to render the documentNo
domainReturns the domain name of the server that loaded the documentYes
formsReturns a collection of all the forms in the documentYes
imagesReturns a collection of all the images in the documentYes
lastModifiedReturns the date and time the document was last modifiedNo
linksReturns a collection of all the links in the documentYes
readyStateReturns the (loading) status of the documentNo
referrerReturns the URL of the document that loaded the current documentYes
titleSets or returns the title of the documentYes
URLReturns the full URL of the documentYes
MethodDescriptionW3C
close()Closes the output stream previously opened with document.open()Yes
getElementsByName()Accesses all elements with a specified nameYes
open()Opens an output stream to collect the output from document.write() or document.writeln()Yes
write()Writes HTML expressions or JavaScript code to a documentYes
writeln()Same as write(), but adds a newline character after each statementYes

 

 

Mouse Events

EventAttributeDescriptionDOM
clickonclickThe event occurs when the user clicks on an element2
dblclickondblclickThe event occurs when the user double-clicks on an element2
mousedownonmousedownThe event occurs when a user presses a mouse button over an element2
mousemoveonmousemoveThe event occurs when a user moves the mouse pointer over an element2
mouseoveronmouseoverThe event occurs when a user mouse over an element2
mouseoutonmouseoutThe event occurs when a user moves the mouse pointer out of an element2
mouseuponmouseupThe event occurs when a user releases a mouse button over an element2

Keyboard Events

EventAttributeDescriptionDOM
keydownonkeydownThe event occurs when the user is pressing a key or holding down a key2
keypressonkeypressThe event occurs when the user is pressing a key or holding down a key2
keyuponkeyupThe event occurs when a keyboard key is released2

 

Frame/Object Events

EventAttributeDescriptionDOM
abortonabortThe event occurs when an image is stopped from loading before completely loaded (for <object>)2
erroronerrorThe event occurs when an image does not load properly (for <object>, <body> and <frameset>) 
loadonloadThe event occurs when a document, frameset, or <object> has been loaded2
resizeonresizeThe event occurs when a document view is resized2
scrollonscrollThe event occurs when a document view is scrolled2
unloadonunloadThe event occurs when a document is removed from a window or frame (for <body> and <frameset>)2

 

Form Events

EventAttributeDescriptionDOM
bluronblurThe event occurs when a form element loses focus2
changeonchangeThe event occurs when the content of a form element, the selection, or the checked state have changed (for <input>, <select>, and <textarea>)2
focusonfocusThe event occurs when an element gets focus (for <label>, <input>, <select>, textarea>, and <button>)2
resetonresetThe event occurs when a form is reset2
selectonselectThe event occurs when a user selects some  text (for <input> and <textarea>)2
submitonsubmitThe event occurs when a form is submitted2

 

Event Object

ConstantDescriptionDOM
AT_TARGETThe current event is in the target phase, i.e. it is being evaluated at the event target (1)2
BUBBLING_PHASEThe current event phase is the bubbling phase (2)2
CAPTURING_PHASEThe current event phase is the capture phase (3)2
PropertyDescriptionDOM
bubblesReturns whether or not an event is a bubbling event2
cancelableReturns whether or not an event can have its default action prevented2
currentTargetReturns the element whose event listeners triggered the event2
eventPhaseReturns which phase of the event flow is currently being evaluated2
targetReturns the element that triggered the event2
timeStampReturns the time (in milliseconds relative to the epoch) at which the event was created2
typeReturns the name of the event2
MethodDescriptionDOM
initEvent()Specifies the event type, whether or not the event can bubble, whether or not the event's default action can be prevented2
preventDefault()To cancel the event if it is cancelable, meaning that any default action normally taken by the implementation as a result of the event will not occur2
stopPropagation()To prevent further propagation of an event during event flow2

 

EventTarget Object

MethodDescriptionDOM
addEventListener()Allows the registration of event listeners on the event target (IE8 = attachEvent())2
dispatchEvent()Allows to send the event to the subscribed event listeners (IE8 = fireEvent())2
removeEventListener()Allows the removal of event listeners on the event target (IE8 = detachEvent())2

 

EventListener Object

MethodDescriptionDOM
handleEvent()Called whenever an event occurs of the event type for which the EventListener interface was registered2

 

DocumentEvent Object

MethodDescriptionDOM
createEvent() 2

 

MouseEvent/KeyboardEvent Object

PropertyDescriptionDOM
altKeyReturns whether or not the "ALT" key was pressed when an event was triggered2
buttonReturns which mouse button was clicked when an event was triggered2
clientXReturns the horizontal coordinate of the mouse pointer, relative to the current window, when an event was triggered2
clientYReturns the vertical coordinate of the mouse pointer, relative to the current window, when an event was triggered2
ctrlKeyReturns whether or not the "CTRL" key was pressed when an event was triggered2
keyIdentifierReturns the identifier of a key3
keyLocationReturns the location of the key on the advice3
metaKeyReturns whether or not the "meta" key was pressed when an event was triggered2
relatedTargetReturns the element related to the element that triggered the event2
screenXReturns the horizontal coordinate of the mouse pointer, relative to the screen, when an event was triggered2
screenYReturns the vertical coordinate of the mouse pointer, relative to the screen, when an event was triggered2
shiftKeyReturns whether or not the "SHIFT" key was pressed when an event was triggered2
MethodDescriptionW3C
initMouseEvent()Initializes the value of a MouseEvent object2
initKeyboardEvent()Initializes the value of a KeyboardEvent object3
 

HTMLElement

PropertyDescriptionW3C
accessKeySets or returns an accesskey for an elementYes
classNameSets or returns the class attribute of an elementYes
clientHeightReturns the viewable height of the content on a page (not including borders, margins, or scrollbars)No
clientWidthReturns the viewable width of the content on a page (not including borders, margins, or scrollbars)No
dirSets or returns the text direction of an elementYes
idSets or returns the id of an elementYes
innerHTMLSets or returns the HTML contents (+text) of an elementYes
langSets or returns the language code for an elementYes
offsetHeightReturns the height of an element, including borders and padding if any, but not marginsNo
offsetLeftReturns the horizontal offset position of the current element relative to its offset containerNo
offsetParentReturns the offset container of an elementNo
offsetTopReturns the vertical offset position of the current element relative to its offset containerNo
offsetWidthReturns the width of an element, including borders and padding if any, but not marginsNo
scrollHeightReturns the entire height of an element (including areas hidden with scrollbars)No
scrollLeftReturns the distance between the actual left edge of an element and its left edge currently in viewNo
scrollTopReturns the distance between the actual top edge of an element and its top edge currently in viewNo
scrollWidthReturns the entire width of an element (including areas hidden with scrollbars)No
styleSets or returns the style attribute of an elementYes
tabIndexSets or returns the tab order of an elementYes
titleSets or returns the title attribute of an elementYes
MethodDescriptionW3C
toString()Converts an element to a stringYes
 
其它HTML DOM对象

Anchor

The Anchor object represents an HTML hyperlink.

For each <a> tag in an HTML document, an Anchor object is created.

An anchor allows you to create a link to another document (with the href attribute), or to a different point in the same document (with the name attribute).

You can access an anchor by using getElementById(), or by searching through the anchors collection property of the Document object.

 
PropertyDescriptionW3C
charsetSets or returns the value of the charset attribute of a linkYes
hrefSets or returns the value of the href attribute of a linkYes
hreflangSets or returns the value of the hreflang attribute of a linkYes
nameSets or returns the value of the name attribute of a linkYes
relSets or returns the value of the rel attribute of a linkYes
revSets or returns the value of the rev attribute of a linkYes
targetSets or returns the value of the target attribute of a linkYes
typeSets or returns the value of the type attribute of a linkYes

Area

The Area object represents an area inside an HTML image-map (an image-map is an image with clickable areas).

For each <area> tag in an HTML document, an Area object is created.

PropertyDescriptionW3C
altSets or returns the value of the alt attribute of an areaYes
coordsSets or returns the value of the coords attribute of an areaYes
hashSets or returns the anchor part of the href attribute valueYes
hostSets or returns the hostname:port part of the href attribute valueYes
hostnameSets or returns the hostname part of the href attribute valueYes
hrefSets or returns the value of the href attribute of an areaYes
noHrefSets or returns the value of the nohref attribute of an areaYes
pathnameSets or returns the pathname part of the href attribute valueYes
portSets or returns the port part of the href attribute valueYes
protocolSets or returns the protocol part of the href attribute valueYes
searchSets or returns the querystring part of the href attribute valueYes
shapeSets or returns the value of the shape attribute of an areaYes
targetSets or returns the value of the target attribute of an areaYes

Base

The Base object represents an HTML base element.

The base element is used to specify a default address or a default target for all links on a page.

For each <base> tag in an HTML document, a Base object is created.

 

PropertyDescriptionW3C
hrefSets or returns the value of the href attribute in a base elementYes
targetSets or returns the value of the target attribute in a base elementYes

Body

The Body object represents the HTML body element.

The body element defines a document's body.

The body element contains all the contents of an HTML document, such as text, hyperlinks, images, tables, lists, etc.

PropertyDescriptionW3C
aLinkSets or returns the value of the alink attribute of the body elementYes
backgroundSets or returns the value of the background attribute of the body elementYes
bgColorSets or returns the value of the bgcolor attribute of the body elementYes
linkSets or returns the value of the link attribute of the body elementYes
textSets or returns the value of the text attribute of the body elementYes
vLinkSets or returns the value of the vlink attribute of the body elementYes
EventDescriptionW3C
onloadScript to be run immediately after a page is loadedYes

Button

The Button object represents a push button.

For each <button> tag, <input type="reset">,  <input type="submit">  or <input type="button"> tag  in an HTML document, a Button object is created.

Inside an HTML button element you can put content, like text or images. This is the difference between this element and buttons created with the input element.

PropertyDescriptionW3C
disabledSets or returns whether a button is disabled, or notYes
formReturns a reference to the form that contains a buttonYes
nameSets or returns the value of the name attribute of a buttonYes
typeSets or returns the type of a buttonYes
valueSets or returns the value of the value attribute of a buttonYes

Form

The Form object represents an HTML form.

For each <form> tag in an HTML document, a Form object is created.

Forms are used to collect user input, and contain input elements like text fields, checkboxes, radio-buttons, submit buttons and more. A form can also contain select menus, textarea, fieldset, legend, and label elements.

Forms are used to pass data to a server.

 

PropertyDescriptionW3C
acceptCharsetSets or returns the value of the accept-charset attribute in a formYes
actionSets or returns the value of the action attribute in a formYes
enctypeSets or returns the value of the enctype attribute in a formYes
lengthReturns the number of elements in a formYes
methodSets or returns the value of the method attribute in a formYes
nameSets or returns the value of the name attribute in a formYes
targetSets or returns the value of the target attribute in a formYes


 

Frame

 

The Frame object represents an HTML frame.

The <frame> tag defines one particular window (frame) within a frameset.

For each <frame> tag in an HTML document, a Frame object is created.


IFrame

The IFrame object represents an HTML inline frame.

The <iframe> tag defines an inline frame that contains another document.

For each <iframe> tag in an HTML document, an IFrame object is created.

PropertyDescriptionW3C
alignSets or returns the value of the align attribute in an iframeYes
contentDocumentReturns the document object generated by a frame/iframeYes
contentWindowReturns the window object generated by a frame/iframeNo
frameBorderSets or returns the value of the frameborder attribute in a frame/iframeYes
heightSets or returns the value of the height attribute in an iframeYes
longDescSets or returns the value of the longdesc attribute in a frame/iframeYes
marginHeightSets or returns the value of the marginheight attribute in a frame/iframeYes
marginWidthSets or returns the value of the marginwidth attribute in a frame/iframeYes
nameSets or returns the value of the name attribute in a frame/iframeYes
noResizeSets or returns the value of the noresize attribute in a frameYes
scrollingSets or returns the value of the scrolling attribute in a frame/iframeYes
srcSets or returns the value of the src attribute in a frame/iframeYes
widthSets or returns the value of the width attribute in an iframeYes
EventDescriptionW3C
onloadScript to be run immediately after a frame/iframe is loadedYes

 

Frameset

The Frameset object represents an HTML frameset.

The HTML frameset element holds two or more frame elements. Each frame element holds a separate document.

The HTML frameset element states only how many columns or rows there will be in the frameset.

PropertyDescriptionW3C
colsSets or returns the value of the cols attribute in a framesetYes
rowsSets or returns the value of the rows attribute in a framesetYes
EventDescriptionW3C
onloadScript to be run immediately after a page is loadedYes
 

Image

The Image object represents an embedded image.

For each <img> tag in an HTML document, an Image object is created.

Notice that images are not technically inserted into an HTML page, images are linked to HTML pages. The <img> tag creates a holding space for the referenced image.

PropertyDescriptionW3C
alignSets or returns the value of the align attribute of an imageYes
altSets or returns the value of the alt attribute of an imageYes
borderSets or returns the value of the border attribute of an imageYes
completeReturns whether or not the browser is finished loading an imageNo
heightSets or returns the value of the height attribute of an imageYes
hspaceSets or returns the value of the hspace attribute of an imageYes
longDescSets or returns the value of the longdesc attribute of an imageYes
lowsrcSets or returns a URL to a low-resolution version of an imageNo
nameSets or returns the name of an imageYes
srcSets or returns the value of the src attribute of an imageYes
useMapSets or returns the value of the usemap attribute of an imageYes
vspaceSets or returns the value of the vspace attribute of an imageYes
widthSets or returns the value of the width attribute of an imageYes
EventThe event occurs when...W3C
onabortLoading of an image is interruptedYes
onerrorAn error occurs when loading an imageYes
onloadAn image is finished loadingYes

 

Checkbox

The Checkbox object represents a checkbox in an HTML form.

Checkboxes let a user select one or more options of a limited number of choices.

For each instance of an <input type="checkbox"> tag in an HTML form, a Checkbox object is created.

You can access a Checkbox object by searching through the elements[] array of a form, or by using document.getElementById().

PropertyDescriptionW3C
disabledSets or returns whether a checkbox is disabled, or notYes
checkedSets or returns the checked state of a checkboxYes
defaultCheckedReturns the default value of the checked attributeYes
formReturns a reference to the form that contains the checkboxYes
nameSets or returns the value of the name attribute of a checkboxYes
typeReturns which type of form element the checkbox isYes
valueSets or returns the value of the value attribute of a checkboxYes

 

FileUpload

The FileUpload object represents a single-line text input control and a browse button, in an HTML form.

This object allow file uploading to a server. Clicking on the browse button opens the file dialog box that allows a user to select a file to upload.

For each <input type="file"> tag in an HTML form, a FileUpload object is created.

You can access a FileUpload object by searching through the elements[] array of the form, or by using document.getElementById().

PropertyDescriptionW3C
disabledSets or returns whether the fileUpload button is disabled, or notYes
acceptSets or returns a comma-separated list of accepted content typesYes
formReturns a reference to the form that contains the FileUpload objectYes
nameSets or returns the value of the name attribute of the FileUpload objectYes
typeReturns which type of form element the FileUpload object isYes
valueReturns the path or the name of the selected fileYes
 

Hidden

The Hidden object represents a hidden input field in an HTML form (this input field is invisible for the user).

With this element you can send hidden form data to a server.

For each <input type="hidden"> tag in an HTML form, a Hidden object is created.

You can access a hidden input field by searching through the elements[] array of the form, or by using document.getElementById().

 
PropertyDescriptionW3C
formReturns a reference to the form that contains the hidden input fieldYes
nameSets or returns the value of the name attribute of the hidden input fieldYes
typeReturns which type of form element a hidden input field isYes
valueSets or returns the value of the value attribute of the hidden input fieldYes

 

Password

The Password object represents a single-line password field in an HTML form.

The content of a password field will be masked (appear as blobs or asterisks) in a browser.

For each <input type="password"> tag in an HTML form, a Password object is created.

You can access a password field by searching through the elements[] array of the form, or by using document.getElementById().

PropertyDescriptionW3C
defaultValueSets or returns the default value of a password fieldYes
disabledSets or returns whether the password field is disabled, or notYes
formReturns a reference to the form that contains the password fieldYes
maxLengthSets or returns the maximum number of characters allowed in a password fieldYes
nameSets or returns the value of the name attribute of a password fieldYes
readOnlySets or returns whether a password field is read-only, or notYes
sizeSets or returns the width of a password field (in number of characters)Yes
typeReturns which type of form element a password field isYes
valueSets or returns the value of the value attribute of the password fieldYes
MethodDescriptionW3C
select()Selects the content of a password fieldYes
 

Radio

The Radio object represents a radio button in an HTML form.

Radio buttons allow the user to select only ONE of a predefined set of options. You define groups with the name property (radio buttons with the same name belong to the same group).

For each <input type="radio"> tag in an HTML form, a Radio object is created.

You can access a radio object by searching through the elements[] array of the form, or by using document.getElementById().

PropertyDescriptionW3C
checkedSets or returns the checked state of a radio buttonYes
defaultCheckedReturns the default value of the checked attributeYes
disabledSets or returns whether the radio button is disabled, or notYes
formReturns a reference to the form that contains the radio buttonYes
nameSets or returns the value of the name attribute of a radio buttonYes
typeReturns which type of form element the radio button isYes
valueSets or returns the value of the value attribute of the radio buttonYes

Text

The Text object represents a single-line text input field in an HTML form.

For each <input type="text"> tag in an HTML form, a Text object is created.

You can access a text input field by searching through the elements[] array of the form, or by using document.getElementById().

 
PropertyDescriptionW3C
defaultValueSets or returns the default value of a text fieldYes
disabledSets or returns whether the text field is disabled, or notYes
formReturns a reference to the form that contains the text fieldYes
maxLengthSets or returns the maximum number of characters allowed in a text fieldYes
nameSets or returns the value of the name attribute of a text fieldYes
readOnlySets or returns whether a text field is read-only, or notYes
sizeSets or returns the width of a text field (in number of characters)Yes
typeReturns which type of form element a text field isYes
valueSets or returns the value of the value attribute of the text fieldYes
MethodDescriptionW3C
select()Selects the content of a text fieldYes
 

Link

The Link object represents an HTML link element.

The link element must be placed inside the head section of an HTML document, and it specifies a link to an external resource.

A common use of the <link> tag is to link to external style sheets.

PropertyDescriptionW3C
charsetSets or returns the character encoding of a linked documentYes
hrefSets or returns the URL of a linked documentYes
hreflangSets or returns the language code of the linked documentYes
mediaSets or returns the media type for the link elementYes
relSets or returns the relationship between the current document and the linked documentYes
revSets or returns the reverse relationship from the linked document to the current documentYes
typeSets or returns the content type of the linked documentYes
 

Meta

The Meta object represents an HTML meta element.

<meta> tags must be placed inside the head section of an HTML document, and they provide metadata about the HTML document.

Meta elements are typically used to specify page description, keywords, author of the document, last modified, and other metadata. Metadata can be used by browsers (e.g. how to display content or reload pages), search engines (e.g. keywords), or other web services.

 
PropertyDescriptionW3C
contentSets or returns the value of the content attribute of a meta elementYes
httpEquivSets or returns an HTTP header for the information in the content attributeYes
nameSets or returns a name for the information in the content attributeYes
schemeSets or returns how the value of content should be interpretedYes
 

Object

The Object object represents an HTML object element.

The <object> tag is used to include objects such as images, audio, videos, Java applets, ActiveX, PDF, and Flash into a webpage.

PropertyDescriptionW3C
alignSets or returns the alignment of the object according to the surrounding textYes
archiveSets or returns a string that can be used to implement your own archive functionality for the objectYes
borderSets or returns the border around the objectYes
codeSets or returns the URL of the file that contains the compiled Java classYes
codeBaseSets or returns the URL of the componentYes
codeType Yes
data Yes
declare Yes
formReturns a reference to the object's parent formYes
heightSets or returns the height of the objectYes
hspaceSets or returns the horizontal margin of the objectYes
nameSets or returns the name of the objectYes
standbySets or returns a message when loading the objectYes
typeSets or returns the content type for data downloaded via the data attributeYes
useMap Yes
vspaceSets or returns the vertical margin of the objectYes
widthSets or returns the width of the objectYes

 

Option

The Option object represents an option in a dropdown list in an HTML form.

For each <option> tag in an HTML form, an Option object is created.

You can access an Option object by searching through the elements[] array of a form, or by using document.getElementById().

PropertyDescriptionW3C
defaultSelectedReturns the default value of the selected attributeYes
disabledSets or returns whether an option is disabled, or notYes
formReturns a reference to the form that contains the optionYes
indexSets or returns the index position of an option in a dropdown listYes
selectedSets or returns the value of the selected attributeYes
textSets or returns the text of an option elementYes
valueSets or returns the value to be sent to the serverYes

Select

The Select object represents a dropdown list in an HTML form.

A dropdown list lets a user select one or more options of a limited number of choices.

For each <select> tag in an HTML form, a Select object is created.

You can access a Select object by searching through the elements[] array of a form, or by using document.getElementById().

CollectionDescriptionW3C
optionsReturns a collection of all the options in a dropdown listYes
PropertyDescriptionW3C
disabledSets or returns whether the dropdown list is disabled, or notYes
formReturns a reference to the form that contains the dropdown listYes
lengthReturns the number of options in a dropdown listYes
multipleSets or returns whether more than one item can be selected from the dropdown listYes
nameSets or returns the name of a dropdown listYes
selectedIndexSets or returns the index of the selected option in a dropdown listYes
sizeSets or returns the number of visible options in a dropdown listYes
typeReturns which type of form element a dropdown list isYes
MethodDescriptionW3C
add()Adds an option to a dropdown listYes
remove()Removes an option from a dropdown listYes
 

Table

The Table object represents an HTML table.

For each <table> tag in an HTML document, a Table object is created.

CollectionDescriptionW3C
cellsReturns a collection of all <td> or <th> elements in a tableNo
rowsReturns a collection of all <tr> elements in a tableYes
tBodiesReturns a collection of all <tbody> elements in a tableYes
PropertyDescriptionW3C
align Deprecated.  Sets or returns the alignment of a table according to surrounding text. Use style.textAlign insteadD
background Deprecated.  Sets or returns the background image of a table. Use style.backgroundinsteadD
bgColor Deprecated.  Sets or returns the background color of a table. Usestyle.backgroundColor insteadD
border Deprecated.  Sets or returns the width of the table border. Use style.border insteadD
captionReturns the caption of a tableYes
cellPaddingSets or returns the amount of space between the cell border and cell contentYes
cellSpacingSets or returns the amount of space between the cells in a tableYes
frameSets or returns which outer-borders (of a table) that should be displayedYes
height Deprecated.  Sets or returns the height of a table. Use style.height insteadD
rulesSets or returns which inner-borders (between the cells) that should be displayed in a tableYes
summarySets or returns a description of the data in a tableYes
tFootReturns a reference to the tfoot element of a tableYes
tHeadReturns a reference to the thead element of a tableYes
width Deprecated.  Sets or returns the width of the table. Use style.width insteadD
MethodDescriptionW3C
createCaption()Creates an empty caption element and adds it to the tableYes
createTFoot()Creates an empty tfoot element and adds it to the tableYes
createTHead()Creates an empty thead element and adds it to the tableYes
deleteCaption()Removes the first caption element from the tableYes
deleteRow()Removes a row from the tableYes
deleteTFoot()Removes the tfoot element from the tableYes
deleteTHead()Removes the thead element from the tableYes
insertRow()Creates an empty tr element and adds it to the tableYes
 
 

td

The td object represents a data cell in an HTML table.

For each <td> tag in an HTML table, a td object is created.


th

The th object represents a table header cell in an HTML table.

For each <th> tag in an HTML table, a th object is created.

 
PropertyDescriptionW3C
abbrSets or returns an abbreviated version of the content in a data cellYes
align Deprecated.  Sets or returns the horizontal alignment of the content in a data cell. Use style.textAlign insteadD
axisSets or returns a comma-separated list of related data cellsYes
background Deprecated.  Sets or returns the background image of a data cell. Usestyle.background insteadD
bgColor Deprecated.  Sets or returns the background color of a table. Usestyle.backgroundColor insteadD
cellIndexReturns the position of a cell in the cells collection of a table rowYes
chSets or returns an alignment character for a data cellYes
chOffSets or returns the horizontal offset of the ch propertyYes
colSpanSets or returns the number of columns a cell should spanYes
headersSets or returns a list of header cell ids for the current data cellYes
height Deprecated.  Sets or returns the height of a data cell. Use style.height insteadD
noWrap Deprecated.  Sets or returns whether the content in a cell can be wrapped. Usestyle.whiteSpace insteadD
rowSpanSets or returns the number of rows a cell should spanYes
vAlignSets or returns the vertical alignment of the content within a cellYes
width Deprecated.  Sets or returns the width of a data cell. Use style.width insteadD

tr

The tr object represents an HTML table row.

For each <tr> tag in an HTML document, a tr object is created.

CollectionDescriptionW3C
cellsReturns a collection of all <td> or <th> elements in a table rowYes
PropertyDescriptionW3C
align Deprecated.  Sets or returns the horizontal alignment of the content within a table row. Use style.textAlign insteadD
bgColor Deprecated.  Sets or returns the background color of a table row. Usestyle.backgroundColor insteadD
chSets or returns an alignment character for cells in a table rowYes
chOffSets or returns the horizontal offset of the ch propertyYes
height Deprecated.  Sets or returns the height of a table row. Use style.height insteadD
rowIndexReturns the position of a row in the rows collection of a tableYes
sectionRowIndexReturns the position of a row in the rows collection of a tbody, thead, or tfootYes
vAlignSets or returns the vertical alignment of the content within a table rowYes
MethodDescriptionW3C
deleteCell()Deletes a cell from the current table rowYes
insertCell()Inserts a cell into the current table rowYes
 

Textarea

The Textarea object represents a text-area in an HTML form.

For each <textarea> tag in an HTML form, a Textarea object is created.

You can access a Textarea object by indexing the elements array (by number or name) of the form or by using getElementById().

PropertyDescriptionW3C
colsSets or returns the width of a text areaYes
defaultValueSets or returns the default value of a text areaYes
disabledSets or returns whether the text area is disabled, or notYes
formReturns a reference to the form that contains the text areaYes
nameSets or returns the name of a text areaYes
readOnlySets or returns whether the contents of a text area is read-onlyYes
rowsSets or returns the height (in rows) of a text areaYes
typeReturns the type of the form element the text area isYes
valueSets or returns the contents of a text areaYes
MethodDescriptionW3C
select()Selects the entire contents of a text areaYes
 

Style对象

The Style object represents an individual style statement.

The Style object can be accessed from the document or from the elements to which that style is applied.

Background properties

PropertyDescriptionW3C
backgroundSets or returns all the background properties in one declarationYes
backgroundAttachmentSets or returns whether a background-image is fixed or scrolls with the pageYes
backgroundColorSets or returns the background-color of an elementYes
backgroundImageSets or returns the background-image for an elementYes
backgroundPositionSets or returns the starting position of a background-imageYes
backgroundRepeatSets or returns how to repeat (tile) a background-imageYes

Border/Outline properties

PropertyDescriptionW3C
borderSets or returns border-width, border-style, and border-color in one declarationYes
borderBottomSets or returns all the borderBottom* properties in one declarationYes
borderBottomColorSets or returns the color of the bottom borderYes
borderBottomStyleSets or returns the style of the bottom borderYes
borderBottomWidthSets or returns the width of the bottom borderYes
borderColorSets or returns the color of an element's border (can have up to four values)Yes
borderLeftSets or returns all the borderLeft* properties in one declarationYes
borderLeftColorSets or returns the color of the left borderYes
borderLeftStyleSets or returns the style of the left borderYes
borderLeftWidthSets or returns the width of the left borderYes
borderRightSets or returns all the borderRight* properties in one declarationYes
borderRightColorSets or returns the color of the right borderYes
borderRightStyleSets or returns the style of the right borderYes
borderRightWidthSets or returns the width of the right borderYes
borderStyleSets or returns the style of an element's border (can have up to four values)Yes
borderTopSets or returns all the borderTop* properties in one declarationYes
borderTopColorSets or returns the color of the top borderYes
borderTopStyleSets or returns the style of the top borderYes
borderTopWidthSets or returns the width of the top borderYes
borderWidthSets or returns the width of an element's border (can have up to four values)Yes
outlineSets or returns all the outline properties in one declarationYes
outlineColorSets or returns the color of the outline around a elementYes
outlineStyleSets or returns the style of the outline around an elementYes
outlineWidthSets or returns the width of the outline around an elementYes

 

Generated Content properties

PropertyDescriptionW3C
contentSets or returns the generated content before or after the elementYes
counterIncrementSets or returns the list of counters and increment valuesYes
counterResetSets or returns the list of counters and their initial valuesYes

 

List properties

PropertyDescriptionW3C
listStyleSets or returns list-style-image, list-style-position, and list-style-type in one declarationYes
listStyleImageSets or returns an image as the list-item markerYes
listStylePositionSets or returns the position of the list-item markerYes
listStyleTypeSets or returns the list-item marker typeYes

Margin/Padding properties

PropertyDescriptionW3C
marginSets or returns the margins of an element (can have up to four values)Yes
marginBottomSets or returns the bottom margin of an elementYes
marginLeftSets or returns the left margin of an elementYes
marginRightSets or returns the right margin of an elementYes
marginTopSets or returns the top margin of an elementYes
paddingSets or returns the padding of an element (can have up to four values)Yes
paddingBottomSets or returns the bottom padding of an elementYes
paddingLeftSets or returns the left padding of an elementYes
paddingRightSets or returns the right padding of an elementYes
paddingTopSets or returns the top padding of an elementYes

 

Misc properties

PropertyDescriptionW3C
cssTextSets or returns the contents of a style declaration as a stringYes

 

Positioning/Layout properties

PropertyDescriptionW3C
bottomSets or returns the bottom position of a positioned elementYes
clearSets or returns the position of the element relative to floating objectsYes
clipSets or returns which part of a positioned element is visibleYes
cssFloatSets or returns the horizontal alignment of an objectYes
cursorSets or returns the type of cursor to display for the mouse pointerYes
displaySets or returns an element's display typeYes
heightSets or returns the height of an elementYes
leftSets or returns the left position of a positioned elementYes
maxHeightSets or returns the maximum height of an elementYes
maxWidthSets or returns the maximum width of an elementYes
minHeightSets or returns the minimum height of an elementYes
minWidthSets or returns the minimum width of an elementYes
overflowSets or returns what to do with content that renders outside the element boxYes
positionSets or returns the type of positioning method used for an element (static, relative, absolute or fixed)Yes
rightSets or returns the right position of a positioned elementYes
topSets or returns the top position of a positioned elementYes
verticalAlignSets or returns the vertical alignment of the content in an elementYes
visibilitySets or returns whether an element should be visibleYes
widthSets or returns the width of an elementYes
zIndexSets or returns the stack order of a positioned elementYes

 

Printing properties

PropertyDescriptionW3C
orphansSets or returns the minimum number of lines for an element that must be visible at the bottom of a pageYes
pageBreakAfterSets or returns the page-break behavior after an elementYes
pageBreakBeforeSets or returns the page-break behavior before an elementYes
pageBreakInsideSets or returns the page-break behavior inside an elementYes
widowsSets or returns the minimum number of lines for an element that must be visible at the top of a pageYes

 

Table properties

PropertyDescriptionW3C
borderCollapseSets or returns whether the table border should be collapsed into a single border, or notYes
borderSpacingSets or returns the space between cells in a tableYes
captionSideSets or returns the position of the table captionYes
emptyCellsSets or returns whether to show the border and background of empty cells, or notYes
tableLayoutSets or returns the way to lay out table cells, rows, and columnsYes

 

Text properties

PropertyDescriptionW3C
colorSets or returns the color of the textYes
directionSets or returns the text directionYes
fontSets or returns font-style, font-variant, font-weight, font-size, line-height, and font-family in one declarationYes
fontFamilySets or returns the font face for textYes
fontSizeSets or returns the font size of the textYes
fontSizeAdjustSets or returns the font aspect valueYes
fontStyleSets or returns whether the style of the font is normal, italic or obliqueYes
fontVariantSets or returns whether the font should be displayed in small capital lettersYes
fontWeightSets or returns the boldness of the fontYes
letterSpacingSets or returns the space between characters in a textYes
lineHeightSets or returns the distance between lines in a textYes
quotesSets or returns the type of quotation marks for embedded quotationsYes
textAlignSets or returns the horizontal alignment of textYes
textDecorationSets or returns the decoration of a textYes
textIndentSets or returns the indentation of the first line of textYes
textShadowSets or returns the shadow effect of a textYes
textTransformSets or returns the case of a textYes
unicodeBidiSets or returns whether the text should be overridden to support multiple languages in the same documentYes
whiteSpaceSets or returns how to handle tabs, line breaks and whitespace in a textYes
wordSpacingSets or returns the spacing between words in a textYes

 

 

本文来源于:http://www.tuicool.com/articles/VbquYb

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值