分享
 
 
 

javascript手冊-d

王朝html/css/js·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

Date object

Lets you work with dates and times.

语法

To create a Date object: 1. dateObjectName = new Date()

2. dateObjectName = new Date("month day, year hours:minutes:seconds")

3. dateObjectName = new Date(year, month, day)

4. dateObjectName = new Date(year, month, day, hours, minutes, seconds)

dateObjectName is either the name of a new object or a property of an existing object.

month, day, year, hours, minutes, and seconds are string values for form 2 of the 语法. For forms 3 and 4, they are integer values.

To use Date methods: dateObjectName.methodName(parameters)

dateObjectName is either the name of an existing Date object or a property of an existing object..

methodName is one of the methods listed below.

Exceptions: The Date object's parse and UTC methods are static methods that you use as follows: Date.UTC(parameters)

Date.parse(parameters)

Property of

None.

描述

The Date object is a built-in JavaScript object.

Form 1 of the 语法 creates today's date and time. If you omit hours, minutes, or seconds from form 2 or 4 of the 语法, the value will be set to zero.

The way JavaScript handles dates is very similar to the way Java handles dates: both languages have many of the same date methods, and both store dates internally as the number of milliseconds since January 1, 1970 00:00:00. Dates prior to 1970 are not allowed.

Properties

None.

Methods

getDate

getDay

getHours

getMinutes

getMonth

getSeconds

getTime

getTimezoneOffset

getYear

parse

setDate

setHours

setMinutes

setMonth

setSeconds

setTime

setYear

toGMTString

toLocaleString

UTC

Event handlers

None. Built-in objects do not have event handlers.

例子

today = new Date()

birthday = new Date("December 17, 1995 03:24:00")

birthday = new Date(95,12,17)

birthday = new Date(95,12,17,3,24,0)

defaultChecked property

A Boolean value indicating the default selection state of a checkbox or radio button.

语法1. checkboxName.defaultChecked

2. radioName[index].defaultChecked

checkboxName is either the value of the NAME attribute of a checkbox object or an element in the elements array.

radioName is the value of the NAME attribute of a radio object.

index is an integer representing a radio button in a radio object.

Property of

checkbox, radio

描述

If an checkbox or radio button is selected by default, the value of the defaultChecked property is true; otherwise, it is false. defaultChecked initially reflects whether the CHECKED attribute is used within an <INPUT> tag; however, setting defaultChecked overrides the CHECKED attribute.

You can set the defaultChecked property at any time. The display of the checkbox or radio button does not update when you set the defaultChecked property, only when you set the checked property.

例子

The following example resets an array of radio buttons called musicType on the musicForm form to the default selection state. function radioResetter() {

var i=""

for (i in document.musicForm.musicType) {

if (document.musicForm.musicType[i].defaultChecked==true) {

document.musicForm.musicType[i].checked=true

}

}

}

See also

checked property

defaultSelected property

A Boolean value indicating the default selection state of an option in a select object.

语法selectName.options[index].defaultSelected

selectName is either the value of the NAME attribute of a select object or an element in the elements array.

index is an integer representing an option in a select object.

Property of

options array

描述

If an option in a select object is selected by default, the value of the defaultSelected property is true; otherwise, it is false. defaultSelected initially reflects whether the SELECTED attribute is used within an <OPTION> tag; however, setting defaultSelected overrides the SELECTED attribute.

You can set the defaultSelected property at any time. The display of the select object does not update when you set the defaultSelected property, only when you set the selected or selectedIndex properties.

A select object created without the MULTIPLE attribute can have only one option selected by default. When you set defaultSelected in such an object, any previous default selections, including defaults set with the SELECTED attribute, are cleared. If you set defaultSelected in a select object created with the MULTIPLE attribute, previous default selections are not affected.

例子

In the following example, the restoreDefault() function returns the musicType select object to its default state. The for loop uses the options array to evaluate every option in the select object. The if statement sets the selected property if defaultSelected is true. function restoreDefault() {

for (var i = 0; i < document.musicForm.musicType.length; i++) {

if (document.musicForm.musicType.options[i].defaultSelected == true) {

document.musicForm.musicType.options[i].selected=true

}

}

}

The previous example assumes that the select object is similar to the following: <SELECT NAME="musicType">

<OPTION SELECTED> R&B

<OPTION> Jazz

<OPTION> Blues

<OPTION> New Age

</SELECT>

See also

index, selected, selectedIndex properties

defaultStatus property

The default message displayed in the status bar at the bottom of the window.

语法windowReference.defaultStatus

windowReference is a valid way of referring to a window, as described in the window object.

Property of

window

描述

The defaultStatus message appears when nothing else is in the status bar. Do not confuse the defaultStatus property with the status property. 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.

You can set the defaultStatus property at any time. You must return true if you want to set the defaultStatus property in the onMouseOver event handler.

例子

In the following example, the statusSetter() function sets both the status and defaultStatus properties in an onMouseOver event handler: function statusSetter() {

window.defaultStatus = "Click the link for the Netscape home page"

window.status = "Netscape home page"

}

<A HREF="http://www.netscape.com"

onMouseOver = "statusSetter(); return true">Netscape</A>

In the previous example, notice that the onMouseOver event handler returns a value of true. You must return true to set status or defaultStatus in an event handler.

See also

status property

defaultValue property

A string indicating the default value of a password, text, or textarea object.

语法1. passwordName.defaultValue

2. textName.defaultValue

3. textareaName.defaultValue

passwordName is either the value of the NAME attribute of a password object or an element in the elements array.

textName is either the value of the NAME attribute of a text object or an element in the elements array.

textareaName is either the value of the NAME attribute of a textarea object or an element in the elements array.

Property of

password, text, textarea

描述

The initial value of defaultValue differs for each object:

For text objects, it initially reflects the value of the VALUE attribute.

For textarea objects, it initially reflects the value specified between the <TEXTAREA> and </TEXTAREA> tags.

For password objects, it initially is null (for security reasons), regardless of the value of the VALUE attribute.

Setting defaultValue programatically overrides the initial setting. If you programatically set defaultValue for the password object and then evaluate it, JavaScript returns the current value.

You can set the defaultValue property at any time. The display of the related object does not update when you set the defaultValue property, only when you set the value property.

例子

The following function evaluates the defaultValue property of objects on the surfCity form and displays the values in the msgWindow window: function defaultGetter() {

msgWindow=window.open("")

msgWindow.document.write("hidden.defaultValue is " +

document.surfCity.hiddenObj.defaultValue + "<BR>")

msgWindow.document.write("password.defaultValue is " +

document.surfCity.passwordObj.defaultValue + "<BR>")

msgWindow.document.write("text.defaultValue is " +

document.surfCity.textObj.defaultValue + "<BR>")

msgWindow.document.write("textarea.defaultValue is " +

document.surfCity.textareaObj.defaultValue + "<BR>")

msgWindow.document.close()

}

See also

value property

document object

Contains information on the current document, and provides methods for displaying htm output to the user.

语法

To define a document object, use standard htm 语法: <BODY

BACKGROUND="backgroundImage"

BGCOLOR="backgroundColor"

TEXT="foregroundColor"

LINK="unfollowedLinkColor"

ALINK="activatedLinkColor"

VLINK="followedLinkColor"

[onLoad="handlerText"]

[onUnload="handlerText"]>

</BODY>

BACKGROUND specifies an image that fills the background of the document.

BGCOLOR, TEXT, LINK, ALINK, and VLINK are color specifications expressed as a hexadecimal RGB triplet (in the format "rrggbb" or "#rrggbb") or as one of the string literals listed in Color Values.

To use a document object's properties and methods: 1. document.propertyName

2. document.methodName(parameters)

propertyName is one of the properties listed below.

methodName is one of the methods listed below.

Property of

window

描述

An htm document consists of a <HEAD> and <BODY> tag. The <HEAD> 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 htm elements for the document) goes within the <BODY> tag.

You can load a new document by using the location object.

You can reference 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.

Properties

alinkColor reflects the ALINK attribute

anchors is an array reflecting all the anchors in a document

bgColor reflects the BGCOLOR attribute

cookie specifies a cookie

fgColor reflects the TEXT attribute

forms is an array reflecting all the forms in a document

lastModified reflects the date a document was last modified

linkColor reflects the LINK attribute

links is an array reflecting all the links in a document

location reflects the complete URL of a document

referrer reflects the URL of the calling document

title reflects the contents of the <TITLE> tag

vlinkColor reflects the VLINK attribute

The following objects are also properties of the document object:

anchor

form

history

link

Methods

clear

close

open

write

writeln

Event handlers

None. The onLoad and onUnload event handlers are specified in the <BODY> tag but are actually event handlers for the window object.

例子

The following example creates two frames, each with one document. The document in the first frame contains links to anchors in the document of the second frame. Each document defines its colors.

DOC0.htm, which defines the frames, contains the following code:

Document object example

DOC1.htm, which defines the content for the first frame, contains the following code:

Some links

Numbers

Colors

Music types

Countries

DOC2.htm, which defines the content for the second frame, contains the following code:

Some numbers

one

two

three

four

five

six

seven

eight

nine

Some colors

red

orange

yellow

green

blue

purple

brown

black

Some music types

R&B

Jazz

Soul

Reggae

Rock

Country

Classical

Opera

Some countries

Afghanistan

Brazil

Canada

Finland

India

Italy

Japan

Kenya

Mexico

Nigeria

See also

frame and window objects

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有