Window object example: Window 2
2007-11-27 17:50:09 来源:WEB开发网unescape function
Returns the ASCII string for the specified value.
语法
unescape(string)
string is a string or a property of an existing object, containing characters in either of the following forms:
描述
The unescape function is not a method associated with any object, but is part of the language itself.
The string returned by the unescape function is a series of characters in the ISO Latin-1 character set.
例子
The following example returns &
unescape(%26)
The following example returns !#
unescape(%21%23)
相关
userAgent property
A string representing the value of the user-agent header sent in the HTTP protocol from client to server.
语法
navigator.userAgent
Property of
navigator
描述
Servers use the value sent in the user-agent header to identify the client.
userAgent is a read-only property.
例子
The following example displays userAgent information for the Navigator:
document.write(The value of navigator.userAgent is + navigator.userAgent)
For Navigator 2.0, this displays the following:
The value of navigator.userAgent is Mozilla/2.0 (Win16; I)
相关
UTC method
Returns the number of milliseconds in a date object since January 1, 1970 00:00:00, Universal Coordinated Time (GMT).
语法
Date.UTC(year, month, day [, hrs] [, min] [, sec])
year is a year after 1900.
month is a month between 0-11.
date is a day of the month between 1-31.
hrs is hours between 0-23.
min is minutes between 0-59.
sec is seconds between 0-59.
用法
Date
描述
UTC takes comma-delimited date parameters and returns the number of milliseconds since January 1, 1970 00:00:00, Universal Coordinated Time (GMT).
Because UTC is a static 用法 Date, you always use it as Date.UTC(), rather than as a 用法 a date object you created.
例子
The following statement creates a date object using GMT instead of local time:
gmtDate = new Date(Date.UTC(96, 11, 1, 0, 0, 0))
相关
value property
A string that is related to the VALUE attribute of its object.
语法
1. objectName.value2. radioName[index].value3. selectName.options.[index].value
objectName is either the value of the NAME attribute of a hidden, password, text, textarea, button, reset, submit or checkbox object or an element in the elements array.
radioName is the value of the NAME attribute of a radio object.
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 a radio button in a radio object or an option in a select object.
Property of
描述
The value property differs for every object.
hidden, text, and textarea objects
The value property is a string that initially reflects the VALUE attribute. This string is displayed in the text and textarea fields. The value of this property changes when a user or a program modifies the field.You can set the value property at any time. The display of the text and textarea objects updates immediately when you set the value property.
password object
The value property is a string that initially reflects the VALUE attribute. This string is represented by asterisks in the password object field. The value of this property changes when a user or a program modifies the field, but the value is always displayed as asterisks.
If you programatically set the value property and then evaluate it, JavaScript returns the current value. If a user interactively modifies the value in the password field, you cannot evaluate it accurately for security reasons.
button, reset, and submit objects
When a VALUE attribute is specified in htm, the value property is a string that reflects it. This string is displayed on the face of the button.
When a VALUE attribute is not specified in htm, the value property differs for each object:
These strings are displayed on the faces of the buttons.
value is a read-only property.
Do not confuse the value property with the name property. The name property is not displayed onscreen; it is used to reference the objects programatically.
options array
The value property is a string that initially reflects the VALUE attribute. The value of this property can change when a program modifies it. The value property is not displayed onscreen, but is returned to the server if the option is selected.
You can set the value property at any time.
Do not confuse the value property with the selection state of the select object or the text that is displayed as an option. The selected and selectedIndex properties determine which options are selected, and the defaultSelected property determines the default selection state. The text that is displayed in each option is specified by its text property.
checkbox and radio objects
When a VALUE attribute is specified in htm, the value property is a string that reflects it. When a VALUE attribute is not specified in htm, the value property is a string that evaluates to on. The value property is not displayed onscreen, but is returned to the server if the radio button or checkbox is selected.
You can set the value property at any time.
Do not confuse the value property with the selection state of the object or the text that is displayed next to each checkbox and radio button. The checked property determines the selection state of the object, and the defaultChecked property determines the default selection state. The text that is displayed is specified following the <INPUT TYPE=checkbox> or the <INPUT TYPE=radio> tag.
例子
The following function evaluates the value property of a group of buttons and displays it in the msgWindow window:
function valueGetter() { var msgWindow=window.open() msgWindow.document.write(submitButton.value is + document.valueTest.submitButton.value + <BR>) msgWindow.document.write(resetButton.value is + document.valueTest.resetButton.value + <BR>) msgWindow.document.write(helpButton.value is + document.valueTest.helpButton.value + <BR>) msgWindow.document.close()}
This example displays the following values:
Query SubmitResetHelp
The previous example assumes the buttons have been defined as follows
<INPUT TYPE=submit NAME=submitButton><INPUT TYPE=reset NAME=resetButton><INPUT TYPE=button NAME=helpButton VALUE=Help>
The following function evaluates the value property of a group of radio buttons and displays it in the msgWindow window:
function valueGetter() { var msgWindow=window.open() for (var i = 0; i < document.valueTest.radioObj.length; i++) { msgWindow.document.write (The value of radioObj[ + i + ] is + document.valueTest.radioObj[i].value +<BR>) } msgWindow.document.close()}
This example displays the following values:
onononon
The previous example assumes the buttons have been defined as follows
<BR><INPUT TYPE=radio NAME=radioObj>R&B<BR><INPUT TYPE=radio NAME=radioObj CHECKED>Soul<BR><INPUT TYPE=radio NAME=radioObj>Rock and Roll<BR><INPUT TYPE=radio NAME=radioObj>Blues
相关
For hidden, password, text, and textarea:
For button, reset, and submit:
For options array:
For checkbox and radio:
vlinkColor property
A string specifying the color of visited links.
语法
document.vlinkColor
Property of
document
描述
The vlinkColor 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 VLINK 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.
例子
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
相关
window object
The top-level object for each document, location, and history object group.
语法
To define a window, use the open method:
windowVar = window.open(URL, windowName [,windowFeatures])windowVar is the name of a new window. Use this variable when referring to a windows properties, methods, and containership.
windowName is the window name to use in the TARGET attribute of a <FORM> or <A> tag.
For details on defining a window, see the open method.
To use a window objects properties and methods:
1. window.propertyName 2. window.methodName(parameters) 3. self.propertyName 4. self.methodName(parameters) 5. top.propertyName 6. top.methodName(parameters) 7. parent.propertyName 8. parent.methodName(parameters) 9. windowVar.propertyName10. windowVar.methodName(parameters)11. propertyName12. methodName(parameters)windowVar is a variable referring to a window object. See the preceding 语法 for defining a window.
propertyName is one of the properties listed below.
methodName is one of the methods listed below.
To define an onLoad or onUnload event handler for a window object, use the <BODY> or <FRAMESET> tags:
<BODY ... [onLoad=handlerText] [onUnload=handlerText]></BODY><FRAMESET ROWS=rowHeightList COLS=columnWidthList [onLoad=handlerText] [onUnload=handlerText]> [<FRAME SRC=locationOrURL NAME=frameName>]</FRAMESET>
For information on the <BODY> and <FRAMESET> tags, see the document and frame objects.
Property of
描述
The window object is the top-level object in the JavaScript client hierarchy. Frame objects are also windows.
The self and window properties are synonyms for the current window, and you can optionally use them to refer to the current window. For example, you can close the current window by calling either window.close() or self.close(). You can use these properties to make your code more readable, or to disambiguate the property reference self.status from a form called status. See the properties and methods listed below for more 例子.
The top and parent properties are also synonyms that can be used in place of the window name. top refers to the top-most Navigator window, and parent refers to a window containing a frameset. See the top and parent properties.
Because the existence of the current window is assumed, you do not have to reference the name of the window when you call its methods and assign its properties. For example, status=Jump to a new location is a valid property assignment, and close() is a valid method call. However, when you open or close a window within an event handler, you must specify window.open() or window.close() instead of simply using open() or close(). Due to the scoping of static objects in JavaScript, a call to close() without specifying an object name is equivalent to document.close().
You can reference a windows frame objects in your code by using the frames array. The frames array contains an entry for each frame in a window with a <FRAMESET> tag.
Windows lack event handlers until some htm is loaded into them containing a <BODY> or <FRAMESET> tag.
Properties
The following objects are also properties of the window object:
Methods
Event handlers
例子
In the following example, the document in the top window opens a second window, window2, and defines pushbuttons that open a message window, write to the message window, close the message window, and close window2. The onLoad and onUnload event handlers of the document loaded into window2 display alerts when the window op
更多精彩
赞助商链接