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 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 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:
Hello, world
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("
The floor of 45.95 is " + Math.floor(45.95))
//Displays the value -46
document.write("
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 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("
" + worldString.fontcolor("salmon") +
" is salmon in this line")
document.write("
" + worldString.fontcolor("red") +
" is red in this line")
document.write("
" + worldString.fontcolor("8000") +
" is maroon in hexadecimal in this line")
document.write("
" + worldString.fontcolor("FA8072") +
" is salmon in hexadecimal in this line")
document.write("
" + worldString.fontcolor("FF00") +
" is red in hexadecimal in this line")
The previous example produces the same output as the following htm:
Hello, world is maroon in this line
Hello, world is salmon in this line
Hello, world is red in this line
Hello, world is maroon in hexadecimal in this line
Hello, world is salmon in hexadecimal in this line
Hello, world 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 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 tag.
例子
The following example uses string methods to change the size of a string:
var worldString="Hello, world"
document.write(worldString.small())
document.write("
" + worldString.big())
document.write("
" + worldString.fontsize(7))
The previous example produces the same output as the following htm:
Hello, world
Hello, world
Hello, world
相关
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=""
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