javascript的Document对象——属性

An HTML document consists of HEAD and BODY tags. The HEAD tag includes information on the document's title and base (the absolute URL base to be used for relative URL links in the document). The BODY tag encloses the body of a document, which is defined by the current URL. The entire body of the document (all other HTML elements for the document) goes within the BODY tag. You can load a new document by setting the Window.location property.

描述

 

 

You can clear the document pane (and remove the text, form elements, and so on so they do not redisplay) with these statements: document.close();
document.open();
document.write();
You can omit the document.open call if you are writing text or HTML, since write does an implicit open of that MIME type if the document stream is closed. You can refer to the anchors, forms, and links of a document by using the anchors, forms, and links arrays. These arrays contain an entry for each anchor, form, or link in a document and are properties of the document object. Do not use location as a property of the document object; use the document.URL property instead. The document.location property, which is a synonym for document.URL, will be removed in a future release.  

alinkColor

 

属性源
document
实现版本 Navigator 2.0

 

描述

 

If you express the color as a hexadecimal RGB triplet, you must use the format rrggbb. For example, the hexadecimal RGB values for salmon are red=FA, green=80, and blue=72, so the RGB triplet for salmon is "FA8072". The following example sets the color of active links using a string literal: document.alinkColor="aqua" The following example sets the color of active links to aqua using a hexadecimal triplet: document.alinkColor="00FFFF" document.bgColor, document.fgColor, document.linkColor, document.vlinkColor

 

示例

 

 

 

参看

 

An array of objects corresponding to named anchors in source order. You can refer to the Anchor objects in your code by using the anchors array. This array contains an entry for each A tag containing a NAME attribute in a document; these entries are in source order. For example, if a document contains three named anchors whose NAME attributes are anchor1, anchor2, and anchor3, you can refer to the anchors either as: document.anchors["anchor1"]
document.anchors["anchor2"]
document.anchors["anchor3"]
or as: document.anchors[0]
document.anchors[1]
document.anchors[2]
To obtain the number of anchors in a document, use the length property: document.anchors.length. If a document names anchors in a systematic way using natural numbers, you can use the anchors array and its length property to validate an anchor name before using it in operations such as setting location.hash. An array of objects corresponding to the applets in a document in source order. You can refer to the applets in your code by using the applets array. This array contains an entry for each Applet object (APPLET tag) in a document; these entries are in source order. For example, if a document contains three applets whose NAME attributes are app1, app2, and app3, you can refer to the anchors either as: document.applets["app1"]
document.applets["app2"]
document.applets["app3"]
or as: document.applets[0]
document.applets[1]
document.applets[2]
A string specifying the color of the document background. The bgColor property is expressed as a hexadecimal RGB triplet or as one of the string literals listed in Appendix B, "Color Values," in the JavaScript Guide. This property is the JavaScript reflection of the BGCOLOR attribute of the BODY tag. The default value of this property is set by the user with the preferences dialog box.

anchors

 

属性源 document
只读
实现版本 Navigator 2.0

 

描述

 

 

 

 

applets

 

属性源 document
只读
实现版本 Navigator 3.0

 

描述

 

 

 

bgColor

 

属性源 document
实现版本 Navigator 2.0

 

描述

 

If you express the color as a hexadecimal RGB triplet, you must use the format rrggbb. For example, the hexadecimal RGB values for salmon are red=FA, green=80, and blue=72, so the RGB triplet for salmon is "FA8072". The following example sets the color of the document background to aqua using a string literal: document.bgColor="aqua" The following example sets the color of the document background to aqua using a hexadecimal triplet: document.bgColor="00FFFF"

 

示例

 

 

 

 

String value representing all of the cookies associated with this document. Navigator 3.0:该属性默认是带有污点的。有关数据污点的更多信息,请看“JavaScript 的安全性”

cookie

 

属性源 document
实现版本 Navigator 2.0

 

安全性

 

A cookie is a small piece of information stored by the web browser in the cookies.txt file. Use string methods such as substring, charAt, indexOf, and lastIndexOf to determine the value stored in the cookie. See the JavaScript Guide for a complete specification of the cookie语法.

描述

 

You can set the cookie property at any time. The "expires=" component in the cookie file sets an expiration date for the cookie, so it persists beyond the current browser session. This date string is formatted as follows: Wdy, DD-Mon-YY HH:MM:SS GMT This format represents the following values:

 

 

 

  • Wdy is a string representing the full name of the day of the week.
  • DD is an integer representing the day of the month.
  • Mon is a string representing the three-character abbreviation of the month.
  • YY is an integer representing the last two digits of the year.
  • HH, MM, and SS are 2-digit representations of hours, minutes, and seconds, respectively.

For example, a valid cookie expiration date is expires=Wednesday, 09-Nov-99 23:12:40 GMT The cookie date format is the same as the date returned by toGMTString, with the following exceptions:

 

 

  • Dashes are added between the day, month, and year.
  • The year is a 2-digit value for cookies.
示例

 

 

 

Specifies the domain name of the server that served a document. Navigator 3.0:该属性默认是带有污点的。有关数据污点的更多信息,请看“JavaScript 的安全性”

domain

 

属性源 document
实现版本 Navigator 3.0

 

安全性

 

Navigator 3.0: The domain property lets scripts on multiple servers share properties when data tainting is not enabled. With tainting disabled, a script running in one window can read properties of another window only if both windows come from the same Web server. But large Web sites with multiple servers might need to share properties among servers. For example, a script on the host www.royalairways.com might need to share properties with a script on the host search.royalairways.com. If scripts on two different servers change their domain property so that both scripts have the same domain name, both scripts can share properties. For example, a script loaded from search.royalairways.com could set its domain property to "royalairways.com". A script from www.royalairways.com running in another window could also set its domain property to "royalairways.com". Then, since both scripts have the domain "royalairways.com", these two scripts can share properties, even though they did not originate from the same server. You can change domain only in a restricted way. Initially, domain contains the hostname of the Web server from which the document was loaded. You can set domain only to a domain suffix of itself. For example, a script from search.royalairways.com can't set its domain property to "search.royalairways". And a script from IWantYourMoney.com cannot set its domain to "royalairways.com". Once you change the domain property, you cannot change it back to its original value. For example, if you change domain from "search.royalairways.com" to "royalairways.com", you cannot reset it to "search.royalairways.com". The following statement changes the domain property to "braveNewWorld.com". This statement is valid only if "braveNewWorld.com" is a suffix of the current domain, such as "www.braveNewWorld.com". document.domain="braveNewWorld.com" An array containing an entry for each object embedded in the document. You can refer to embedded objects (created with the EMBED tag) in your code by using the embeds array. This array contains an entry for each EMBED tag in a document in source order. For example, if a document contains three embedded objects whose NAME attributes are e1, e2, and e3, you can refer to the objects either as:

描述

 

 

 

 

 

示例

 

 

embeds

 

属性源 document
只读
实现版本 Navigator 3.0

 

描述

 

document.embeds["e1"]
document.embeds["e2"]
document.embeds["e3"]
or as: document.embeds[0]
document.embeds[1]
document.embeds[2]
Elements in the embeds array may have public callable functions, if they refer to a plug-in that uses LiveConnect. See the JavaScript Guide.

 

Use the elements in the embeds array to interact with the plug-in that is displaying the embedded object. If a plug-in is not Java-enabled, you cannot do anything with its element in the embeds array. The fields and methods of the elements in the embeds array vary from plug-in to plug-in; see the documentation supplied by the plug-in manufacturer. When you use the EMBED tag to generate output from a plug-in application, you are not creating a Plugin object.

 

The following code includes an audio plug-in in a document. <EMBED SRC="train.au" HEIGHT=50 WIDTH=250>

示例

 

 

A string specifying the color of the document (foreground) text. The fgColor property is expressed as a hexadecimal RGB triplet or as one of the string literals listed in Appendix B, "Color Values," in the JavaScript Guide. This property is the JavaScript reflection of the TEXT attribute of the BODY tag. The default value of this property is set by the user with the preferences dialog box You cannot set this property after the HTML source has been through layout.

fgColor

 

属性源 document
实现版本 Navigator 2.0

 

描述

 

If you express the color as a hexadecimal RGB triplet, you must use the format rrggbb. For example, the hexadecimal RGB values for salmon are red=FA, green=80, and blue=72, so the RGB triplet for salmon is "FA8072". You can override the value set in the fgColor property in either of the following ways:

 

 

  • Setting the COLOR attribute of the FONT tag.
  • Using the fontcolor method.

formName

属性源
document
实现版本 Navigator 3.0

 

An array containing an entry for each form in the document. Navigator 3.0:该属性默认是带有污点的。有关数据污点的更多信息,请看“JavaScript 的安全性”

forms

 

属性源 document
只读
实现版本 Navigator 3.0

 

安全性

 

You can refer to the forms in your code by using the forms array (you can also use the form name). This array contains an entry for each Form object (FORM tag) in a document; these entries are in source order. For example, if a document contains three forms whose NAME attributes are form1, form2, and form3, you can refer to the objects in the forms array either as:

描述

 

document.forms["form1"]
document.forms["form2"]
document.forms["form3"]
or as: document.forms[0]
document.forms[1]
document.forms[2]
Additionally, the document object has a separate property for each named form, so you could refer to these forms also as: document.form1
document.form2
document.form3
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. The value of each element in the forms array is <object nameAttribute>, where nameAttribute is the NAME attribute of the form. An array containing an entry for each image in the document. You can refer to the images in a document by using the images array. This array contains an entry for each Image object (IMG tag) in a document; the entries are in source order. Images created with the Image constructor are not included in the images array. For example, if a document contains three images whose NAME attributes are im1, im2, and im3, you can refer to the objects in the images array either as:

 

 

 

 

images

 

属性源 document
只读
实现版本 Navigator 3.0

 

document.images["im1"]
document.images["im2"]
document.images["im3"]
or as: document.images[0]
document.images[1]
document.images[2]
A string representing the date that a document was last modified. Navigator 3.0:该属性默认是带有污点的。有关数据污点的更多信息,请看“JavaScript 的安全性”

 

lastModified

 

属性源 document
只读
实现版本 Navigator 2.0

 

安全性

 

The lastModified property is derived from the HTTP header data sent by the web server. Servers generally obtain this date by examining the file's modification date. The last modified date is not a required portion of the header, and some servers do not supply it. If the server does not return the last modified information, JavaScript receives a 0, which it displays as January 1, 1970 GMT. The following code checks the date returned by lastModified and prints out a value that corresponds to unknown. lastmod = document.lastModified // get string of last modified date
lastmoddate = Date.parse(lastmod)   // convert modified string to date
if(lastmoddate == 0){               // unknown date (or January 1, 1970 GMT)
   document.writeln("Lastmodified: Unknown")
   } else {
   document.writeln("LastModified: " + lastmod)
}
In the following example, the lastModified property is used in a SCRIPT tag at the end of an HTML file to display the modification date of the page: document.write("This page updated on " + document.lastModified) The layers property is an array containing an entry for each layer within the document. You can refer to the layers in your code by using the layers array. This array contains an entry for each Layer object (LAYER or ILAYER tag) in a document; these entries are in source order. For example, if a document contains three layers whose NAME attributes are layer1, layer2, and layer3, you can refer to the objects in the layers array either as:

描述

 

 

 

示例

 

 

layers

 

属性源 document
实现版本 Navigator 4.0

 

描述

 

document.layers["layer1"]
document.layers["layer2"]
document.layers["layer3"]
or as: document.layers[0]
document.layers[1]
document.layers[2]
When accessed by integer index, array elements appear in z-order from back to front, where 0 is the bottommost layer and higher layers are indexed by consecutive integers. The index of a layer is not the same as its zIndex property, as the latter does not necessarily enumerate layers with consecutive integers. Adjacent layers can have the same zIndex property values. These are valid ways of accessing layer objects: document.layerName
document.layers【索引】
document.layers["layerName"]
// example of using layers property to access nested layers:
document.layers["parentlayer"].layers["childlayer"]
Elements of a layers array are JavaScript objects that cannot be set by assignment, though their properties can be set. For example, the statement document.layers[0]="music" is invalid (and ignored) because it attempts to alter the layers array. However, the properties of the objects in the array readable and some are wri表. For example, the statement document.layers["suspect1"].left = 100; is valid. This sets the layer's horizontal position to 100. The following example sets the background color to blue for the layer bluehouse which is nested in the layer houses. document.layers["houses"].layers["bluehouse"].bgColor="blue"; A string specifying the color of the document hyperlinks. The linkColor property is expressed as a hexadecimal RGB triplet or as one of the string literals listed in the JavaScript Guide. This property is the JavaScript reflection of the LINK attribute of the BODY tag. The default value of this property is set by the user with the preferences dialog box. You cannot set this property after the HTML source has been through layout.

 

 

 

 

 

 

linkColor

 

属性源 document
实现版本 Navigator 2.0

 

描述

 

If you express the color as a hexadecimal RGB triplet, you must use the format rrggbb. For example, the hexadecimal RGB values for salmon are red=FA, green=80, and blue=72, so the RGB triplet for salmon is "FA8072". The following example sets the color of document links to aqua using a string literal: document.linkColor="aqua" The following example sets the color of document links to aqua using a hexadecimal triplet: document.linkColor="00FFFF"

 

示例

 

 

 

An array of objects corresponding to Area and Link objects in source order. Navigator 3.0:该属性默认是带有污点的。有关数据污点的更多信息,请看“JavaScript 的安全性”

links

 

属性源 document
只读
实现版本 Navigator 2.0

 

安全性

 

You can refer to the Area and Link objects in your code by using the links array. This array contains an entry for each Area (<AREA HREF="..."> tag) and Link (<A HREF="..."> tag) object in a document in source order. It also contains links created with the link method. For example, if a document contains three links, you can refer to them as:

描述

 

document.links[0]
document.links[1]
document.links[2]
An array of objects corresponding to Plugin objects in source order.

plugins

 

属性源 document
只读
实现版本 Navigator 3.0

You can refer to the Plugin objects in your code by using the plugins array. This array contains an entry for each Plugin object in a document in source order. For example, if a document contains three plugins, you can refer to them as:

document.plugins[0]
document.plugins[1]
document.plugins[2]
Specifies the URL of the calling document when a user clicks a link. Navigator 3.0:该属性默认是带有污点的。有关数据污点的更多信息,请看“JavaScript 的安全性”

referrer

 

属性源 document
只读
实现版本 Navigator 2.0

 

安全性

 

When a user navigates to a destination document by clicking a Link object on a source document, the referrer property contains the URL of the source document. referrer is empty if the user typed a URL in the Location box, or used some other means to get to the current URL. referrer is also empty if the server does not provide environment variable information. In the following example, the getReferrer function is called from the destination document. It returns the URL of the source document. function getReferrer() {
   return document.referrer
}
A string representing the title of a document. Navigator 3.0:该属性默认是带有污点的。有关数据污点的更多信息,请看“JavaScript 的安全性”

描述

 

 

 

示例

 

 

title

 

属性源 document
只读
实现版本 Navigator 2.0

 

安全性

 

The title property is a reflection of the value specified between the TITLE start and end tags. If a document does not have a title, the title property is null. In the following example, the value of the title property is assigned to a variable called docTitle: var newWindow = window.open("http://home.netscape.com")
var docTitle = newWindow.document.title
A string specifying the complete URL of the document. Navigator 3.0:该属性默认是带有污点的。有关数据污点的更多信息,请看“JavaScript 的安全性”

描述

 

 

示例

 

 

URL

 

属性源 document
只读
实现版本 Navigator 2.0

 

安全性

 

URL is a string-valued property containing the full URL of the document. It usually matches what window.location.href is set to when you load the document, but redirection may change location.href. The following example displays the URL of the current document: document.write("The current URL is " + document.URL)

描述

 

 

示例

 

 

A string specifying the color of visited links. The vlinkColor property is expressed as a hexadecimal RGB triplet or as one of the string literals listed in the JavaScript Guide. This property is the JavaScript reflection of the VLINK attribute of the BODY tag. The default value of this property is set by the user with the preferences dialog box. You cannot set this property after the HTML source has been through layout.

vlinkColor

 

属性源 document
实现版本 Navigator 2.0

 

描述

 

If you express the color as a hexadecimal RGB triplet, you must use the format rrggbb. For example, the hexadecimal RGB values for salmon are red=FA, green=80, and blue=72, so the RGB triplet for salmon is "FA8072". The following example sets the color of visited links to aqua using a string literal: document.vlinkColor="aqua" The following example sets the color of active links to aqua using a hexadecimal triplet: document.vlinkColor="00FFFF"

 

示例

 

 

 

 
The document object contains a separate property for each form in the document. The name of this property is the value of its NAME attribute. See Form for information on Form objects. You cannot add new forms to the document by creating new properties, but you can modify the form by modifying this object. The following function uses the cookie property to record a reminder for users of an application. The cookie expiration date is set to one day after the date of the reminder. function RecordReminder(time, expression) {
   // Record a cookie of the form "@<T>=<E>" to map
   // from <T> in milliseconds since the epoch,
   // returned by Date.getTime(), onto an encoded expression,
   // <E> (encoded to contain no white space, semicolon,
   // or comma characters)
   document.cookie = "@" + time + "=" + expression + ";"
   // set the cookie expiration time to one day
   // beyond the reminder time
   document.cookie += "expires=" + cookieDate(time + 24*60*60*1000)
   // cookieDate is a function that formats the date
   //according to the cookie spec
}
A string specifying the color of an active link (after mouse-button down, but before mouse-button up). The alinkColor property is expressed as a hexadecimal RGB triplet or as one of the string literals listed in Appendix B, "Color Values," in the JavaScript Guide This property is the JavaScript reflection of the ALINK attribute of the BODY tag. You cannot set this property after the HTML source has been through layout.

 

 

 

 

属性
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值