分享
 
 
 

javascript手冊-f

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

fgColor property

A string specifying the color of the document text.

语法 document.fgColor

Property of

document

描述

The fgColor property is expressed as a hexadecimal RGB triplet or as one of the string literals listed in Color Values . 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 on the Colors tab of the Preferences dialog box, which is displayed by choosing General Preferences from the Options menu. You cannot set this property after the htm source has been through layout.

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.

例子

The following example sets the color of the foreground text to aqua using a string literal: document.fgColor="aqua"

The following example sets the color of the foreground text to aqua using a hexadecimal triplet: document.fgColor="00FFFF"

相关

alinkColor , bgColor , linkColor , and vlinkColor properties

fontcolor

fixed method

Causes a string to be displayed in fixed-pitch font as if it were in a <TT> tag.

语法 stringName .fixed()

stringName is any string or a property of an existing object.

方法

string

描述

Use the fixed method with the write or writeln methods to format and display a string in a document.

例子 The following example uses the fixed method to change the formatting of a string: var worldString="Hello, world"

document.write(worldString.fixed())

The previous example produces the same output as the following htm: <TT>Hello, world</TT>

floor method

Returns the greatest integer less than or equal to a number.

语法 Math.floor( number )

number is any numeric expression or a property of an existing object.

方法

Math

例子 //Displays the value 45

document.write("<P>The floor of 45.95 is " + Math.floor(45.95))

//Displays the value -46

document.write("<P>The floor of -45.95 is " + Math.floor(-45.95))

相关

ceil method

focus method

Gives focus to the specified object.

语法 1. passwordName .focus()

2. selectName .focus()

3. textName .focus()

4. textareaName .focus()

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

selectName is either the value of the NAME attribute of a select 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.

方法

password , select , text , textarea

描述

Use the focus method to navigate to a specific form element and give it focus. You can then either programatically enter a value in the element or let the user enter a value.

例子

In the following example, the checkPassword function confirms that a user has entered a valid password. If the password is not valid, the focus method returns focus to the password object and the select method highlights it so the user can re-enter the password. function checkPassword(userPass) {

if (badPassword) {

alert("Please enter your password again.")

userPass.focus()

userPass.select()

}

} This example assumes that the password is defined as: <INPUT TYPE="password" NAME="userPass">

相关

blur , select methods

fontcolor method

Causes a string to be displayed in the specified color as if it were in a <FONT COLOR= color > tag.

语法 stringName .fontcolor( color )

stringName is any string or a property of an existing object.

color is a string or a property of an existing object, expressing the color as a hexadecimal RGB triplet or as one of the string literals listed in Color Values .

方法

string

描述

Use the fontcolor method with the write or writeln methods to format and display a string in a document.

If you express 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 fontcolor method overrides a value set in the fgColor property.

例子 The following example uses the fontcolor method to change the color of a string var worldString="Hello, world"

document.write(worldString.fontcolor("maroon") +

" is maroon in this line")

document.write("<P>" + worldString.fontcolor("salmon") +

" is salmon in this line")

document.write("<P>" + worldString.fontcolor("red") +

" is red in this line")

document.write("<P>" + worldString.fontcolor("8000") +

" is maroon in hexadecimal in this line")

document.write("<P>" + worldString.fontcolor("FA8072") +

" is salmon in hexadecimal in this line")

document.write("<P>" + worldString.fontcolor("FF00") +

" is red in hexadecimal in this line")

The previous example produces the same output as the following htm: <FONT COLOR="maroon">Hello, world</FONT> is maroon in this line

<P><FONT COLOR="salmon">Hello, world</FONT> is salmon in this line

<P><FONT COLOR="red">Hello, world</FONT> is red in this line

<FONT COLOR="8000">Hello, world</FONT> is maroon in hexadecimal in this line

<P><FONT COLOR="FA8072">Hello, world</FONT> is salmon in hexadecimal in this line

<P><FONT COLOR="FF00">Hello, world</FONT> is red in hexadecimal in this line

fontsize method

Causes a string to be displayed in the specified font size as if it were in a <FONTSIZE= size > tag.

语法 stringName .fontsize( size )

stringName is any string or a property of an existing object.

size is an integer between one and seven, or a string representing a signed integer between 1 and 7, or a property of an existing object.

方法

string

描述

Use the fontsize method with the write or writeln methods to format and display a string in a document. When you specify size as an integer, you set the size of stringName to one of the seven defined sizes. When you specify size as a string such as "-2", you adjust the font size of stringName relative to the size set in the <BASEFONT> tag.

例子 The following example uses string methods to change the size of a string: var worldString="Hello, world"

document.write(worldString.small())

document.write("<P>" + worldString.big())

document.write("<P>" + worldString.fontsize(7))

The previous example produces the same output as the following htm: <SMALL>Hello, world</SMALL>

<P><BIG>Hello, world</BIG>

<P><FONTSIZE=7>Hello, world</FONTSIZE>

相关

big , small methods

form object ( forms array)

Lets users input text and make choices from form objects such as checkboxes, radio buttons, and selection lists. You can also use a form to post data to a server.

语法

To define a form, use standard htm 语法 with the addition of the onSubmit event handler: <FORM

NAME=" formName "

TARGET=" windowName "

ACTION=" serverURL "

METHOD=GET | POST

ENCTYPE=" encodingType "

[onSubmit=" handlerText "]>

</FORM>

NAME="formName" specifies the name of the form object.

TARGET="windowName" specifies the window that form responses go to. When you submit a form with a TARGET attribute, server responses are displayed in the specified window instead of the window that contains the form. windowName can be an existing window; it can be a frame name specified in a <FRAMESET> tag; or it can be one of the literal frame names _top, _parent, _self, or _blank; it cannot be a JavaScript expression (for example, it cannot be parent .frameName or windowName.frameName ). Some values for this attribute may require specific values for other attributes. See RFC 1867 for details. You can access this value using the target property.

ACTION="serverURL" specifies the URL of the server to which form field input information is sent. This attribute can specify a CGI or LiveWire application on the server; it can also be a mailto: URL if the form is to be mailed. See the location object for a 描述 of the URL components. Some values for this attribute may require specific values for other attributes. See RFC 1867 for details. You can access this value using the action property.

METHOD=GET | POST specifies how information is sent to the server specified by ACTION . GET (the default) appends the input information to the URL which on most receiving systems becomes the value of the environment variable QUERY_STRING . POST sends the input information in a data body which is available on stdin with the data length set in the environment variable CONTENT_LENGTH . Some values for this attribute may require specific values for other attributes. See RFC 1867 for details. You can access this value using the method property.

ENCTYPE="encodingType" specifies the MIME encoding of the data sent: "application/x-www-form-urlencoded" (the default) or "multipart/form-data". Some values for this attribute may require specific values for other attributes. See RFC 1867 for details. You can access this value using the encoding property.

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

2. formName . methodName ( parameters )

3. forms[ index ]. propertyName

4. forms[ index ]. methodName ( parameters )

formName is the value of the NAME attribute of a form object.

propertyName is one of the properties listed below.

methodName is one of the methods listed below.

index is an integer representing a form object.

Property of

document

描述

Each form in a document is a distinct object.

You can reference a form's elements in your code by using the element's name (from the NAME attribute) or the elements array. The elements array contains an entry for each element (such as a checkbox, radio, or text object) in a form.

The forms array

You can reference 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 in source order. For example, if a document contains three forms, these forms are reflected as document.forms[0] , document.forms[1] , and document.forms[2] .

To use the forms array: 1. document.forms[ index ]

2. document.forms.length

index is an integer representing a form in a document.

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

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

Elements in the forms array are read-only. For example, the statement document.forms[0]="music" has no effect.

The value of each element in the forms array is <object nameAttribute > , where nameAttribute is the NAME attribute of the form.

Properties

The form object has the following properties:

action reflects the ACTION attribute

elements is an array reflecting all the elements in a form

encoding reflects the ENCTYPE attribute

length reflects the number of elements on a form

method reflects the METHOD attribute

target reflects the TARGET attribute

The following objects are also properties of the form object:

button

checkbox

hidden

password

radio

reset

select

submit

text

textarea

The forms array has the following properties:

length reflects the number of forms in a document

Methods

submit

Event handlers

onSubmit

例子

Example 1: named form. The following example creates a form called form1 that contains text fields for first name and last name. The form also contains two buttons that change the names to all upper case or all lower case. The function setCase shows how to refer to the form by its name.

Form object example

First name:

Last name:

Example 2: forms array. The onLoad event handler in the following example displays the name of the first form in an alert dialog box.

If the form name is musicType , the alert displays the following message: You are looking at the form!

Example 3: onSubmit event handler. The following example shows an onSubmit event handler that determines whether to submit a form. The form contains one text object where the user enters three characters. The onSubmit event handler calls a function, checkData , that returns true if the number of characters is three; otherwise, it returns false. Notice that the form's onSubmit event handler, not the submit button's onClick event handler, calls the checkData function. Also, the onSubmit event handler contains a return statement that returns the value obtained with the function call.

Form object/onSubmit event handler example

Form object example

Enter 3 characters:

Example 4: submit method. The following example is similar to the previous one, except it submits the form using the submit method instead of a submit object. The form's onSubmit event handler does not prevent the form from being submitted. The form uses a button's onClick event handler to call the checkData function. If the value is valid, the checkData function submits the form by calling the form's submit method.

Form object/submit method example

Enter 3 characters:

相关

button , checkbox , hidden , password , radio , reset , select , submit , text , textarea objects

forms property

An array of objects corresponding to the forms (<FORM> tags) in a document in source order. See form object.

forward method

Loads the next URL in the history list.

语法 history.forward()

方法

history

描述

This method performs the same action as a user choosing the Forward button in the Navigator. The forward method is the same as history.go(1) .

例子 The following custom buttons perform the same operations as the Navigator Back and Forward buttons: <P><INPUT TYPE="button" VALUE="< Back"

onClick="history.back()">

<P><INPUT TYPE="button" VALUE="> Forward"

onClick="history.forward()">

相关

back , go methods

frame object ( frames array)

A window that can display multiple, independently scrollable frames on a single screen, each with its own distinct URL. Frames can point to different URLs and be targeted by other URLs, all within the same screen. A series of frames makes up a page.

语法

To define a frame object, use standard htm 语法. The onLoad and onUnload event handlers are specified in the <FRAMESET> tag but are actually event handlers for the window object: <FRAMESET

ROWS=" rowHeightList "

COLS=" columnWidthList "

[onLoad=" handlerText "]

[onUnload=" handlerText "]>

[<FRAME SRC=" locationOrURL " NAME=" frameName ">]

</FRAMESET>

ROWS="rowHeightList" is a comma-separated list of values specifying the row-height of the frame. An optional suffix defines the units. Default units are pixels.

COLS="columnWidthList" is a comma-separated list of values specifying the column-width of the frame. An optional suffix defines the units. Default units are pixels.

<FRAME> defines a frame.

SRC="locationOrURL" specifies the URL of the document to be displayed in the frame. The URL cannot include an anchor name; for example <FRAME SRC="doc2.htm#colors" NAME="frame2"> is invalid. See the location object for a 描述 of the URL components.

NAME="frameName" specifies a name to be used as a target of hyperlink jumps.

To use a frame object's properties: 1. [ windowReference .] frameName . propertyName

2. [ windowReference .]frames[ index ]. propertyName

3. window. propertyName

4. self. propertyName

5. parent. propertyName

windowReference is a variable windowVar from a window definition (see window object), or one of the synonyms top or parent.

frameName is the value of the NAME attribute in the <FRAME> tag of a frame object.

index is an integer representing a frame object.

propertyName is one of the properties listed below.

Property of

The frame object is a property of window

The frames array is a property of both frame and window

描述

The <FRAMESET> tag is used in an htm document whose sole purpose is to define the layout of frames that make up a page. Each frame is a window object.

If a <FRAME> tag contains SRC and NAME attributes, you can refer to that frame from a sibling frame by using parent. frameName or parent.frames[ index ] . For example, if the fourth frame in a set has NAME="homeFrame", sibling frames can refer to that frame using parent.homeFrame or parent.frames[3] .

The self and window properties are synonyms for the current frame, and you can optionally use them to refer to the current frame. You can use these properties to make your code more readable. See the properties listed below for 例子.

The top and parent properties are also synonyms that can be used in place of the frame name. top refers to the top-most window that contains frames or nested framesets, and parent refers to the window containing the current frameset. See the top and parent properties.

The frames array

You can reference the frame objects in your code by using the frames array. This array contains an entry for each child frame (<FRAME> tag) in a window containing a <FRAMESET> tag in source order. For example, if a window contains three child frames, these frames are reflected as parent.frames[0] , parent.frames[1] , and parent.frames[2] .

To use the frames array: 1. [ frameReference .]frames[ index ]

2. [ frameReference .]frames.length

3. [ windowReference .]frames[ index ]

4. [ windowReference .]frames.length

frameReference is a valid way of referring to a frame, as described in the frame object.

windowReference is a variable windowVar from a window definition (see window object), or one of the synonyms top or parent.

index is an integer representing a frame in a parent window.

To obtain the number of child frames in a window or frame, use the length property: [ windowReference .].frames.length

[ frameReference .].frames.length

Elements in the frames array are read-only. For example, the statement windowReference .frames[0]="frame1" has no effect.

The value of each element in the frames array is <object nameAttribute > , where nameAttribute is the NAME attribute of the frame.

Properties

The frame object has the following properties:

frames is an array reflecting all the frames in a window

name reflects the NAME attribute of the <FRAME> tag

length reflects the number of child frames within a frame

parent is a synonym for the window or frame containing the current frameset

self is a synonym for the current frame

window is a synonym for the current frame

The frames array has the following properties:

length reflects the number of child frames within a frame

Methods

clearTimeout

setTimeout

Event handlers

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

例子

The following example creates two windows, each with four frames. In the first window, the first frame contains pushbuttons that change the background colors of the frames in both windows.

FRAMSET1.htm, which defines the frames for the first window, contains the following code:

Frames and Framesets: Window 1

FRAMSET2.htm, which defines the frames for the second window, contains the following code:

Frames and Framesets: Window 2

FRAMCON1.htm, which defines the content for the first frame in the first window, contains the following code:

Frame1

Click here to load a different file into frame 2.

FRAMCON2.htm, which defines the content for the remaining frames, contains the following code:

This is a frame.

FRAMCON3.htm, which is referenced in a link object in FRAMCON1.htm, contains the following code:

This is a frame. What do you think?

相关

document and window objects

frames property

An array of objects corresponding to child frames (<FRAME> tag) in source order. See frame object.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
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- 王朝網路 版權所有