|
JavaScript的对象
The following objects are available in JavaScript:
NOTE: Each object topic indicates whether the object is part of the client (in Navigator), server (in LiveWire), or is common (built-in to JavaScript). Server objects are not included in this version of the documentation. anchor object (client)An anchor is a piece of text identified as the target of a hypertext link. SyntaxTo define an anchor, use standard HTML syntax : <A NAME="anchorName" anchorText </A> NAME specifies a tag that becomes an available hypertext target within the current document.
DescriptionYou can reference the anchor objects in your code by using the anchors property of the document object. The anchors property is an array that contains an entry for each anchor in a document. xxx to be supplied PropertiesMethodsEvent handlersNone. ExamplesWelcome to JavaScriptSee alsoapplet object (client)Represents a Java applet. xxx NYI. Syntaxxxx to be supplied DescriptionThe applet object executes applets written in Java, not JavaScript. Java applets execute only on Netscape 2.0 and HotJava, and only on 32-bit platforms, such as Windows 95, Windows NT, and Unix. They do not execute on the 16-bit Windows platforms, such as Windows 3.1. PropertiesMethodsEvent handlersExamplesxxx to be supplied See alsobutton object (client)A button object is a pushbutton on an HTML form. Syntax<INPUT TYPE="button" NAME="objectName" VALUE="buttonText" [onClick="handlerText"]>NAME specifies the name of the button object as a property of the enclosing form object and can be accessed using the name property. VALUE specifies the label to display on the button face and can be accessed using the value property. DescriptionThe button object is a custom button that you can use to perform an action you define. PropertiesMethodsEvent handlersExamplesA custom button does not necessarily load a new page into the client; it merely executes the script specified by the onClick event handler. In the following example, myfunction() is a JavaScript function. See alsocheckbox object (client)A checkbox object is a checkbox on an HTML form. A checkbox is a toggle switch that lets the user set a value on or off. SyntaxTo define a checkbox, use standard HTML syntax with the addition of the onClick event handler: <INPUT TYPE="checkbox" NAME="objectName" [CHECKED] [onClick="handlerText"]> textToDisplay DescriptionUse the checked property to specify whether the checkbox is currently checked. Use the defaultChecked property to specify whether the checkbox is checked when the form is loaded. PropertiesMethodsEvent handlersExamplesR&B Jazz Blues New Age See alsoDate object (common)JavaScript has a date object that enables you to work with dates and times. JavaScript handles dates very similar to the way Java handles dates: They have many of the same date methods, and both languages store dates internally as the number of milliseconds since January 1, 1970 00:00:00. SyntaxTo create a date object: varName = new Date(parameters)where varName is a JavaScript variable name for the date object being created; it can be a new object or a property of an existing object. The parameters for the Date constructor can be any of the following:
To use date methods: dateObj.methodName(parameters) Exceptions: The UTC and parse methods of date are static methods that you use as follows: Date.UTC(params) Date.parse(params) DescriptionJavaScript does not have a date data type. However, the date object and its methods enable you to work with dates and times in your applications. The date object has a large number of methods for setting, getting, and manipulating dates. PropertiesNone. MethodsEvent handlersNone. Built-in objects do not have event handlers. Examplesxxx to be supplied See alsodocument object (client)The document object contains information on the current document. SyntaxTo define a document object, use standard HTML syntax with the addition of the onLoad and onUnLoad event handlers: <BODY BACKGROUND="backgroundImage" BGCOLOR="#backgroundColor" FGCOLOR="#foregroundColor" LINK="#unfollowedLinkColor" ALINK="#activatedLinkColor" VLINK="#followedLinkColor" [onLoad="handlerText"] [onUnLoad="handlerText"]> </BODY> BGCOLOR, FGCOLOR, LINK, ALINK, and VLINK are color names or color specifications in the format "#rrggbb". DescriptionThe <BODY>... tag encloses an entire 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 reference the anchors, forms, and links of a document by using the anchors, forms, and links properties. These properties are arrays that contain an entry for each anchor, form, or link in a document. The document object's title property reflects the contents of <TITLE>.... Other properties reflect the contents of the document; for example, bgColor reflects the background color, and lastModified reflects the time last modified. Some of the properties are reflections from HTML attributes; for example, the links property is a reflection of all the links in the document, and the forms property is a reflection of all the forms in the document. PropertiesMethodsEvent handlersExamplesxxx to be supplied See alsoform object (client)A form 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 or retrieve data from a server. SyntaxTo define a form, use standard HTML syntax with the addition of the onSubmit event handler: <FORM NAME="objectName TARGET="windowName" ACTION="serverURL" METHOD=GET | POST [onSubmit="handlerText"]> </FORM> TARGET specifies the window that form responses go to. When you submit a form with a TARGET attribute, instead of seeing the server's responses in the same window that contained the form, you see them in a (possibly new) window.
DescriptionEach form in a document corresponds to a distinct object. You can reference the form objects in your code by using the forms property of the document object. The forms property is an array that contains an entry for each form in a document. You can reference a form's elements in your code by using the elements property. The elements property is an array that contains an entry for each element (such as a checkbox, radioButton, or text object) in a form. PropertiesMethodsEvent handlersExamplesxxx to be supplied See alsohistory object (client)The history object contains information on the URLs that the client has visited. This information is stored in a history list, and is accessible through the Navigator's Go menu. Syntaxhistory.go(delta)delta is an integer representing the offset of the destination URL in the history list. DescriptionThe history object is a linked list of URLs the user has visited, as shown in the Navigator's Go menu. PropertiesMethodsEvent handlersNone. ExamplesThe following example goes to the URL the user visited three clicks ago. See alsolink object (client)A link is a piece of text identified as a hypertext link. When the user clicks the link text, the link hypertext reference is loaded into its target window. SyntaxTo define a link, use standard HTML syntax with the addition of the onClick and onMouseOver event handlers: <A HREF=locationOrURL TARGET="windowName" [onClick="handlerText"] [onMouseOver="handlerText"]> linkText </A> HREF identifies a destination anchor or URL.
DescriptionEach link object is a location object. You can reference the link objects in your code by using the links property of the document object. The links property is an array that contains an entry for each link in a document. PropertiesMethodsEvent handlersExamplesThe following example creates a hypertext link to an anchor named javascript_intro. The following example creates a hypertext link to a URL. See alsolocation object (client)The location object contains information on the current URL. Syntaxlocation.propertyproperty is one of the properties listed below. Descriptionxxx to be supplied PropertiesMethodsEvent handlersNone. Examplesxxx to be supplied See alsoMath object (common)The built-in Math object has properties and methods for mathematical constants and functions. For example, the Math object's PI property has the value of pi. SyntaxMath.propertyName or Math.methodName(parameters) DescriptionYou reference the constant PI as Math.PI. Constants are defined with the full precision of real numbers in JavaScript. Similarly, you reference Math functions as methods. For example, the sine function is Math.sin(argument), where argument is the argument. It is often convenient to use the with statement when a section of code uses several Math constants and methods, so you don't have to type "Math" repeatedly. For example, with Math { a = PI * r*r; y = r*sin(theta) x = r*cos(theta) } PropertiesMethodsEvent handlersNone. Built-in objects do not have event handlers. Examplesxxx to be supplied See alsopassword object (client)A password object is a text field on an HTML form. When the user enters text into the field, asterisks (*) hide anything entered from view. SyntaxTo define a password object, use standard HTML syntax: <INPUT TYPE="password" NAME="objectName" [VALUE="textValue"] SIZE=integer Descriptionxxx to be supplied PropertiesMethodsEvent handlersNone. Examples
See alsoradioButton object (client)A radioButton object is a set of radio buttons on an HTML form. A set of radio buttons lets the user choose one item from a list. SyntaxTo define a set of radio buttons, use standard HTML syntax with the addition of the onClick event handler: <INPUT TYPE="radio" NAME="objectName" VALUE="buttonValue" [CHECKED] [onClick="handlerText"]> textToDisplay NAME should contain the same value for all radio buttons in a group. DescriptionAll radio buttons in a radio button group use the same name property. To access the individual radio buttons in your code, follow the object name with an index starting from zero, one for each button the same way you would for an array such as forms: document.forms[0].objectName[0] is the first, document.forms[0].objectName[1] is the second, etc. PropertiesMethodsEvent handlersExamplesThe following example defines a radio button group to choose among three catalogs. Each radio button is given the same name, NAME="choice", forming a group of buttons for which only one choice can be selected. The example also defines a text field that defaults to what was chosen via the radio buttons but that allows the user to type a nonstandard catalog name as well. JavaScript automatically sets the catalog name input field based on the radio buttons. See alsoreset object (client)A reset object is a reset button on an HTML form. SyntaxTo define a reset button, use standard HTML syntax with the addition of the onClick event handler: <INPUT [NAME="objectName"] TYPE="reset" VALUE="buttonText" [onClick="handlerText"]>VALUE specifies the text to display on the button face and can be accessed using the value property. DescriptionA reset button resets all elements in a form to their defaults. PropertiesMethodsEvent handlersExamplesThe following example displays a text object containing "CA". If the user types a different state abbreviation in the text object and then clicks the Clear Form button, the original value of "CA" is restored.
See alsoselection object (client)A selection object is a selection list or scrolling list on an HTML form. A selection list lets the user choose one item from a list. A scrolling list lets the user choose one or more items from a list. SyntaxTo define a selection object, use standard HTML syntax with the addition of the onBlur, onChange, and onFocus event handlers: <SELECT NAME="objectName" [SIZE="value"] [MULTIPLE] [onBlur="handlerText"] [onChange="handlerText"] [onFocus="handlerText"]> <OPTION [SELECTED]> textToDisplay [ ... <OPTION> textToDisplay] </SELECT> SIZE specifies the number of options visible when the form is displayed. DescriptionYou can reference the options of a selection object in your code by using the options property. The options property is an array that contains an entry for each option in a selection object. Each option has the properties listed below. The options on selection objects can be updated dynamically. xxx NYI. PropertiesThe selection object has the following properties: The options property has the following properties: MethodsEvent handlersExamplesThe following example displays a selection list. Choose the music types for your free CDs:
See alsostring object (common)A string object consists of a series of characters. SyntaxstringName.property|methodstringName is the name of a string variable. property is one of the properties listed below. method is one of the methods listed below. DescriptionA string can be represented as a literal enclosed by single or double quotes; for example, "Netscape" or 'Netscape'. PropertiesMethodsEvent handlersNone. Built-in objects do not have event handlers. ExamplesThe following statement creates a string variable. last_name.length is 8.
See alsosubmit object (client)A submit object is a submit button on an HTML form. SyntaxTo define a submit button, use standard HTML syntax with the addition of the onClick event handler: <INPUT TYPE="submit" NAME="objectName" VALUE="buttonText" [onClick="handlerText"]>VALUE specifies the text to display on the button face and can be accessed using the value property. DescriptionA submit button causes a form to be submitted. Clicking a submit button submits a form to the program specified by the form's action property. This action always loads a new page into the client; it may be the same as the current page, if the action so specifies or is not specified. PropertiesMethodsEvent handlersExamplesSee alsotext object (client)A text object is a text input field on an HTML form. A text field lets the user enter a word, phrase, or series of numbers. SyntaxTo define a text object, use standard HTML syntax with the addition of the onBlur, on Change, onFocus, and onSelect event handlers: <INPUT TYPE="text" NAME="objectName" VALUE="textValue" SIZE=integer [onBlur="handlerText"] [onChange="handlerText"] [onFocus="handlerText"] [onSelect="handlerText"]> Descriptiontext objects can be updated dynamically by setting this.value xxx to be supplied PropertiesMethodsEvent handlersExamplesSee alsotextArea object (client)A textArea object is a multiline input field on an HTML form. A textArea field lets the user enter words, phrases, or numbers. SyntaxTo define a text area, use standard HTML syntax with the addition of the onBlur, onChange, onFocus, and onSelect event handlers: <TEXTAREA NAME="objectName" ROWS="integer" COLS="integer" [onBlur="handlerText"] [onChange="handlerText"] [onFocus="handlerText"] [onSelect="handlerText"]> textToDisplay </TEXTAREA> textToDisplay allows only ASCII text, and new lines are respected.
DescriptiontextArea objects can be updated dynamically. xxx need to explain how. (see text object) PropertiesMethodsEvent handlersExamplesSee alsowindow object (client)A window object is the top-level object for each document, location, and history object group. Syntaxxxx to be suppliedDescriptionThe window object is the top-level object in the JavaScript client hierarchy. Because the existence of the current window is assumed, you don't 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. 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 assignment self.status from a form called status. See the methods and properties listed below for more examples. You can reference a window's frame objects in your code by using the frames property. The frames property is an array that contains an entry for each frame in a window. PropertiesMethodsEvent handlersExamplesxxx to be supplied See also回目录
|