JavaScript 的对象属性

转载 2004年08月20日 15:25:00
 

JavaScript 的对象属性

以下的属性可在 JavaScript中用到:

action alinkColor anchors bgColor checked current defaultChecked defaultSelected defaultStatus defaultValue E elements fgColor forms frames hash host hostname href index lastModified length linkColor links LN2 LN10 loadedDate location method name options parent pathname PI port protocol referrer search selected selectedIndex self SQRT1_2 SQRT2 status target text title top value vlinkColor window

action property

String value of a FORM tag's ACTION attribute.

 

Applies to

form

Examples

xxx Examples to be supplied.


alinkColor property

RGB value for color of activated links (after mouse-button down, but before mouse-button up), expressed as a hexadecimal triplet. This property is the JavaScript reflection of the ALINK attribute of the HTML BODY tag.

 

Applies to

document

Examples

xxx Examples to be supplied.


anchors property

Array of objects corresponding to named anchors (<A NAME=""> tags) in source order.

The anchors array contains an entry for each anchor in a document. For example, if a document contains three anchors, these anchors are reflected as document.anchors[0], document.anchors[1], and document.anchors[2].

To obtain the number of anchors in a document, use the length property: document.anchors.length.

 

Applies to

document

Examples

xxx Examples to be supplied.

See also

length property

bgColor property

RGB value of background color, expressed as a hexadecimal triplet. This property is the JavaScript reflection of the BGCOLOR attribute of the HTML BODY tag.

 

Applies to

document

Examples

xxx Examples to be supplied.


checked property

For checkbox, Boolean, false if not checked, true if checked. For radioButton, Boolean, false if not pressed, true if pressed.

 

Applies to

checkbox, radioButton

Examples

xxx To be supplied.


current property

URL of current page. xxx Not yet implemented in Beta 4.

 

Applies to

history

Examples

xxx Examples to be supplied.


defaultChecked property

For checkbox, Boolean property that indicates if the element is selected by default, by the CHECKED attribute. For radioButton, Boolean property that indicates if the element is selected by default, by the CHECKED attribute.

 

Applies to

checkbox, radioButton

Examples

xxx Examples to be supplied.


defaultSelected property

Boolean property that indicates if the option is selected by default, by the presence of the SELECTED attribute in the HTML OPTION tag.

 

Applies to

selection

Examples

xxx Examples to be supplied.


defaultStatus property

For a window, the defaultStatus property reflects the default message displayed in the status bar at the bottom of the window. Do not confuse defaultStatus with status. The status property reflects a priority or transient message in the status bar, such as the message that appears when a mouseOver event occurs over an anchor.

 

Applies to

window

Examples

xxx Examples to be supplied.


defaultValue property

For text and textArea, string, the initial contents of the field.

 

Applies to

password, text, textArea

Examples

xxx Examples to be supplied.


E property

E is Euler's constant, the base of natural logarithms, roughly 2.718.

 

Applies to

Math

Examples

xxx Examples to be supplied.


elements property (client)

Array of objects corresponding to form elements (such as checkbox, radioButton, and text objects) in source order.

The elements array contains an entry for each object in a form. For example, if a form has a text field, a radio button group, and a checkbox, these elements are reflected as formName.elements[0], formName.elements[1], and formName.elements[2].

 

Applies to

form

Examples

xxx Examples to be supplied.


fgColor property

RGB value of foreground (text) color, expressed as a hexadecimal triplet. This property is the JavaScript reflection of the FGCOLOR attribute of the HTML BODY tag.

 

Applies to

document

Examples

xxx Examples to be supplied.


forms property

Array of objects corresponding to named forms (<FORM NAME=""> tags) in source order.

The forms array contains an entry for each form object in a document. For example, if a document contains three forms, these forms are reflected as document.forms[0], document.forms[1], and document.forms[2].

You can refer to a form's elements by using the forms array. For example, you would refer to a text object named quantity in the second form as:

document.forms[1].quantity
You would refer to the value property of this text object as:
document.forms[1].quantity.value

To obtain the number of forms in a document, use the length property: document.forms.length.

 

Applies to

document

Examples

xxx Examples to be supplied.

See also

length property

frames property

Array of objects corresponding to child frame windows (<FRAMESET> tag) in source order.

The frames array contains an entry for each child frame in a window. For example, if a window contains three child frames, these frames are reflected as window.frames[0], window.frames[1], and window.frames[2].

To obtain the number of number of child frames in a window, use the length property: window.frames.length.

 

Applies to

window

Examples

xxx Examples to be supplied.

See also

length property

hash property

The anchor name following the # symbol.

 

Applies to

location

Examples

xxx Examples to be supplied.


host property

The hostname:port part of the location or URL.

 

Applies to

location

Examples

xxx Examples to be supplied.

See also

hostname

hostname property

The hostname part of the location or URL.

 

Applies to

location

Examples

xxx Examples to be supplied.

See also

host

href property

The entire URL as a JavaScript string.

 

Applies to

location

Examples

xxx Examples to be supplied.


index property

For radioButton, number, the ordinal number of the radioButton field, 0-based. For a select object option, the number identifying the position of the option in the selection, starting from zero.

 

Applies to

radioButton, selection

Examples

xxx Examples to be supplied.


lastModified property

A string containing the last-modified date.

 

Applies to

document

Examples

xxx Examples to be supplied.


length property

For a history object, the length of the history list. For a string object, the integer length of the string. For a radioButton object, the number of radio buttons in the object. For an anchors, forms, frames, links, or options array, the number of elements in the array.

For a null string, length is zero.

 

Applies to

applet, history, radioButton, string objects anchors, forms, frames, links, options properties

Examples

xxx Example with history to be supplied.

If the string object mystring is "netscape", then mystring.length returns the integer 8.

If the current document contains five forms, then document.forms.length returns the integer 5.


linkColor property

RGB value for color of hyperlinks, expressed as a hexadecimal triplet.

 

Applies to

document

Examples

xxx Examples to be supplied.


links property

Array of objects corresponding to link objects (<A HREF=URL> tags) in source order.

The links array contains an entry for each link object in a document. For example, if a document contains three link objects, these links are reflected as document.links[0], document.links[1], and document.links[2].

To obtain the number of links in a document, use the length property: document.links.length.

 

Applies to

document

Examples

xxx Examples to be supplied.

See also

length property

LN2 property

LN2 is the natural logarithm of two, roughly 0.693.

 

Applies to

Math

Examples

xxx Examples to be supplied.


LN10 property

LN10 is the natural logarithm of ten, roughly 2.302.

 

Applies to

Math

Examples

xxx Examples to be supplied.


loadedDate property

xxx Description to be supplied. Not yet implemented in Beta 4.

 

Applies to

document

Examples

xxx Examples to be supplied.


location property

The full URL of the document.

 

Applies to

document

Examples

xxx Examples to be supplied.


method property

Value of METHOD attribute, "get" or "post".

 

Applies to

form

Examples

xxx Examples to be supplied.


name property

A string whose value is the same as the NAME attribute of the object. Note that for button, reset, and submit objects, this is the internal name for the button, not the label that appears onscreen.

 

Applies to

button, checkbox, form, password, radioButton, reset, submit, text, textArea

Examples

xxx Examples to be supplied.


options property

Array of objects corresponding to options in a selection object (<OPTION> tags) in source order.

The options array contains an entry for each option in a selection object. For example, if a selection object named musicStyle contains three options, these options are reflected as musicStyle.options[0], musicStyle.options[1], and musicStyle.options[2].

To obtain the number of options in a selection object, use the length property: objectName.options.length.

 

Applies to

selection

Examples

xxx Examples to be supplied.

See also

length property

parent property

In a <FRAMESET> and <FRAME> relationship, the <FRAMESET> window.

 

Applies to

window

Examples

xxx Examples to be supplied.


pathname property

The file or object path name following the third slash.

 

Applies to

location

Examples

xxx Examples to be supplied.


PI property

Pi is the ratio of the circumference of a circle to its diameter, roughly 3.1415.

 

Applies to

Math

Examples

xxx Examples to be supplied.


port property

The port number in a URL, if any; otherwise "".

 

Applies to

location

Examples

xxx Examples to be supplied.


protocol property

The initial substring up to and including the first colon, which indicates the URL's access method.

 

Applies to

location

Examples

xxx Examples to be supplied.


referrer property

xxx Description to be supplied.

 

Applies to

document

Examples

xxx Examples to be supplied.


search property

Any query string or form data after ?.

 

Applies to

location

Examples

xxx Examples to be supplied.


selected property

Boolean property that indicates the current selected state of an option in a select object.

 

Applies to

selection

Examples

xxx Examples to be supplied.


selectedIndex property

xxx to be described

 

Applies to

selection

Examples

xxx Examples to be supplied.


self property

The self property refers to the current window. Use the self property to disambiguate a window property from a form of the same name. You can also use the self property to make your code more readable.

 

Applies to

window

Examples

In the following example, self.status is used to set the status property. This usage disambiguate the status property of a window from a form called "status".

<A HREF="" onClick="this.href=pickRandomURL();" onMouseOver="self.status='Pick a random URL' ; return true"> Go!</A>

See also

window property

SQRT1_2 property

SQRT1_2 is the square root of one-half; equivalently, one over the square root of two, roughly 0.707.

 

Applies to

Math

Examples

xxx Examples to be supplied.


SQRT2 property

SQRT2 is the square root of two, roughly 1.414.

 

Applies to

Math

Examples

xxx Examples to be supplied.


status property

For a window, the status property reflects a priority or transient message in the status bar at the bottom of the window, such as the message that appears when a mouseOver event occurs over an anchor. Do not confuse status with defaultStatus. The defaultStatus property reflects the default message displayed in the status bar.

 

Applies to

window

Examples

Suppose you have created a JavaScript function called pickRandomURL() that lets you select a URL at random. You can use the onClick event handler of an anchor to specify a value for the HREF attribute of the anchor dynamically, and the onMouseOver event handler to specify a custom message for the window in the status property:

<A HREF="" onClick="this.href=pickRandomURL();" onMouseOver="self.status='Pick a random URL'; return true"> Go!</A>

In the above example, the status property of the window is assigned to the window's self property, as self.status. As this example shows, you must return true to set the status property in the onMouseOver event handler.


target property

Window targeted for form response after the form has been submitted.

 

Applies to

form, link

Examples

xxx Examples to be supplied.


text property

String, reflection of the text after the <OPTION> tag.

 

Applies to

selection

Examples

xxx Examples to be supplied.


title property

Current document title.

 

Applies to

document

Examples

xxx Examples to be supplied.


top property

The top-most ancestor window, which is its own parent.

 

Applies to

window

Examples

xxx Examples to be supplied.


value property

For button, reset, and submit objects, a string that is the same as the VALUE attribute (this is the label that appears onscreen, not the internal name for the button). For checkbox, a string, "on" if item is checked; "off" otherwise. For radioButton, a string, reflection of the VALUE attribute. For selection, reflection of VALUE attribute, sent to server on submit. For text and textArea, string, the contents of the field.

Applies to

button, checkbox, password, radioButton, reset, selection, submit, text, textArea

Examples

xxx Examples to be supplied.


vlinkColor property

RGB value for color of visited links, expressed as a hexadecimal triplet. This property is the JavaScript reflection of the VLINK attribute of the HTML BODY tag.

 

Applies to

document

Examples

xxx Examples to be supplied.


window property

The window property refers to the current window. Use the window property to disambiguate a property of the window object from a form of the same name. You can also use the window property to make your code more readable.

 

Applies to

window

Examples

In the following example, window.status is used to set the status property. This usage disambiguate the status property of a window from a form called "status".

<A HREF="" onClick="this.href=pickRandomURL();" onMouseOver="window.status='Pick a random URL' ; return true"> Go!</A>

See also

self property

访问javascript对象的属性和方法

之前就没认真看过,一直就知道定义一个对象,然后用‘.’操作来访问属性和方法。今天突然看见还有另外一种方法,就认真看了下。 var obj={}; var arr=[]; arr[0]=1,arr...
  • angeljsl
  • angeljsl
  • 2015年10月30日 16:46
  • 1126

javascript 创建对象,访问对象的属性,访问对象的方法。

/* 1.在 JavaScript中,几乎所有的事物都是对象。 2.JavaScript 语句向浏览器发出的命令。语句的作用是告诉浏览器该做什么。 ...
  • zhanggaofeixy
  • zhanggaofeixy
  • 2016年08月07日 20:49
  • 1597

javascript 监听对象属性的变化

许多优秀的MVVM框架都实现了数据的双向绑定。Vue.js采用监听-回调的方式来实现一向功能。监听回调的一般写法是这样的:    obj.watch(pro,function(new_value,...
  • huangbinzhang
  • huangbinzhang
  • 2016年12月01日 11:16
  • 2656

JavaScript[对象.属性]集锦

  • 2008年04月14日 09:26
  • 162B
  • 下载

JavaScript中对象的prototype属性代码实例

  • 2011年09月13日 20:51
  • 1KB
  • 下载

JavaScript[对象.属性]集锦、事件查询综合

  • 2013年09月17日 09:36
  • 187KB
  • 下载

JavaScript内置对象属性及方法大全

  • 2009年11月12日 17:58
  • 11KB
  • 下载

js 实现 JavaScript遍历对象中的所有属性

  • 2010年03月30日 14:56
  • 459B
  • 下载

轻松学习 JavaScript(7):对象属性描述符

(点击上方公众号,可快速关注)英文: Dhananjay Kumar   译文:码农网/小峰http://www.codeceo.com/article/easy-javascript-07-obje...
  • VhWfR2u02Q
  • VhWfR2u02Q
  • 2018年01月11日 00:00
  • 74

JavaScript中操作对象的属性

1.操作对象的属性 注意: 标签属性与DOM对象属性的对应关系: 绝大部分2者是相同的,如:imgobj.src属性对应中src属性,但也有例外,如中,操作class属性用divobj.cl...
  • bluedream1219
  • bluedream1219
  • 2015年07月30日 18:27
  • 530
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:JavaScript 的对象属性
举报原因:
原因补充:

(最多只允许输入30个字)