站内搜索: 请输入搜索关键词

当前页面: 开发资料首页Javascript 专题javascript手冊-u-z

javascript手冊-u-z

摘要: javascript
<textarea readonly style="border:none;font-family:Courier New;line-height:150%;width:760px;overflow-y:visible">

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:

  • "%integer", where integer is a number between 0 and 255 (decimal)
  • "hex", where hex is a number between 0x0 and 0xFF (hexadecimal)

    描述

    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("&")
    
    

    The following example returns "!#"

    unescape("%21%23")
    
    

    相关

  • escape function

    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)

    相关

  • appName, appVersion, appCodeName properties

    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))
    
    

    相关

  • parse method

    value property

    A string that is related to the VALUE attribute of its object.

    语法

    1. objectName.value
    
    2. radioName[index].value
    
    3. 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

  • button, checkbox, hidden, password, radio, reset, submit, text, textarea objects
  • options array

    描述

    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:

  • For button, it is an empty string
  • For reset, it is the string "Reset"
  • For submit, it is the string "Submit Query"

    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 + "
    ") msgWindow.document.write("resetButton.value is " + document.valueTest.resetButton.value + "
    ") msgWindow.document.write("helpButton.value is " + document.valueTest.helpButton.value + "
    ") msgWindow.document.close() }

    This example displays the following values:

    Query Submit
    
    Reset
    
    Help
    
    

    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 +"
    ") } msgWindow.document.close() }

    This example displays the following values:

    on
    
    on
    
    on
    
    on
    
    

    The previous example assumes the buttons have been defined as follows


    <input TYPE="radio" NAME="radioObj">R&B
    <input TYPE="radio" NAME="radioObj" CHECKED>Soul
    <input TYPE="radio" NAME="radioObj">Rock and Roll
    <input TYPE="radio" NAME="radioObj">Blues

    相关

    For hidden, password, text, and textarea:

  • defaultValue property

    For button, reset, and submit:

  • name property

    For options array:

  • defaultSelected, selected, selectedIndex, text properties

    For checkbox and radio:

  • checked, defaultChecked properties

    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"
    
    

    相关

  • alinkColor, bgColor, fgColor, and linkColor properties

    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 window's properties, methods, and containership.
    windowName is the window name to use in the TARGET attribute of a <form> or tag.

    For details on defining a window, see the open method.

    To use a window object's 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.propertyName
    
    10. windowVar.methodName(parameters)
    
    11. propertyName
    
    12. 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 tags:

    <body
    
       ...
    
       [onLoad=""]
    
       [onUnload="handlerText"]>
    
    </body>
    
    
    
       []
    
    
    
    

    For information on the <body> and tags, see the document and frame objects.

    Property of

  • None.

    描述

    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 window's frame objects in your code by using the frames array. The frames array contains an entry for each frame in a window with a tag.

    Windows lack event handlers until some htm is loaded into them containing a <body> or tag.

    Properties

  • defaultStatus reflects the default message displayed in the window's status bar
  • frames is an array reflecting all the frames in a window
  • length reflects the number of frames in a parent window
  • name reflects the windowName argument
  • parent is a synonym for the windowName argument and refers to a window containing a frameset
  • self is a synonym for the windowName argument and refers to the current window
  • status specifies a priority or transient message in the window's status bar
  • top is a synonym for the windowName argument and refers to the top-most Navigator window
  • window is a synonym for the windowName argument and refers to the current window

    The following objects are also properties of the window object:

  • document
  • frame
  • location

    Methods

  • alert
  • close
  • confirm
  • open
  • prompt
  • setTimeout
  • clearTimeout

    Event handlers

  • onLoad
  • onUnload

    例子

    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 opens and closes.

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

    <htm> &lt;head&gt; <TITLE>Window object example: Window 1</TITLE> &lt;/head&gt; &lt;body BGCOLOR="antiquewhite"&gt; window2=open("win2.htm","secondWindow","scrollbars=yes,width=250, height=400") document.writeln("<B>The first window has no name: " + window.name + "</B>") document.writeln("<BR><B>The second window is named: " + window2.name + "</B>") &lt;form NAME="form1"&gt; <P>&lt;input TYPE="button" VALUE="Open a message window" onClick="window3=window.open('','messageWindow','scrollbars=yes,width=175, height=300')"&gt; <P>&lt;input TYPE="button" VALUE="Write to the message window" onClick="window3.document.writeln('Hey there');window3.document.close()"&gt; <P>&lt;input TYPE="button" VALUE="Close the message window" onClick="window3.close()"&gt; <P>&lt;input TYPE="button" VALUE="Close window2" onClick="window2.close()"&gt; &lt;/form&gt; &lt;/body&gt; </htm>

    WIN2.htm, which defines the content for window2, contains the following code:

    <htm> &lt;head&gt; <TITLE>Window object example: Window 2</TITLE> &lt;/head&gt; &lt;body BGCOLOR="oldlace" onLoad="alert('Message from ' + window.name + ': Hello, World.')" onUnload="alert('Message from ' + window.name + ': I\'m closing')"&gt; <B>Some numbers</B> <LI>one <LI>two <LI>three <LI>four <LI>five <LI>six <LI>seven <LI>eight <LI>nine &lt;/body&gt; </htm>

    相关 the example for the frame object.

    相关

  • document and frame objects

    window property

    The window property is a synonym for the current window or frame.

    语法

    1. window.propertyName
    
    2. window.methodName
    
    

    propertyName is the defaultStatus, status, length, or name property when the calling window refers to a window object.
    propertyName is the length or name property when the calling window refers to a frame object.
    methodName is any method associated with the window object.

    Property of

    frame, window

    描述

    The window property refers to the current window or frame.

    Although you can use the window property as a synonym for the current frame, your code is more readable if you use the self property. For example, window.name and self.name both specify the name of the current frame, but self.name is easier to understand.

    Use the window property to disambiguate a property of the window object from a form or form element of the same name. You can also use the window property to make your code more readable.

    The window property is read-only. The value of the window property is

         nameAttribute>where nameAttribute is the NAME attribute if window refers to a frame, or an internal reference if window refers to a window.
    
    

    例子

    In the following example, window.status is used to set the status property of the current window. This usage disambiguates the status property of the current window from a form called "status" within the current window.

    Go!

    相关

  • self property

    write method

    Writes one or more htm expressions to a document in the specified window.

    语法

    document.write(expression1 [,expression2], ...[,expressionN])
    expression1 through expressionN are any JavaScript expressions or the properties of existing objects.

    用法

    document

    描述

    The write method displays any number of expressions in a document window. You can specify any JavaScript expression with the write method, including numerics, strings, or logicals.

    The write method is the same as the writeln method, except the write method does not append a newline character to the end of the output.

    Use the write method within any <script> tag or within an event handler. Event handlers execute after the original document closes, so the write method will implicitly open a new document of mimeType text/htm if you do not explicitly issue a document.open() method in the event handler.

    例子

    In the following example, the write method takes several arguments, including strings, a numeric, and a variable:
    var mystery = "world"
    
    // Displays Hello world testing 123
    
    msgWindow.document.write("Hello ", mystery, " testing ", 123)
    
    
    In the following example, the write method takes two arguments. The first argument is an assignment expression, and the second argument is a string literal.
    //Displays Hello world...
    
    msgWindow.document.write(mystr = "Hello "+ "world...")
    
    
    In the following example, the write method takes a single argument that is a conditional expression. If the value of the variable age is less than 18, the method displays "Minor". If the value of age is greater than or equal to 18, the method displays "Adult".
    msgWindow.document.write(status = (age >= 18) ? "Adult" : "Minor")
    
    

    相关

  • close, clear, open, writeln methods

    writeln method

    Writes one or more htm expressions to a document in the specified window and follows them with a newline character.

    语法

    document.writeln(expression1 [,expression2], ...[,expressionN])
    expression1 through expressionN are any JavaScript expressions or the properties of existing objects.

    用法

    document

    描述

    The writeln method displays any number of expressions in a document window. You can specify any JavaScript expression, including numerics, strings, or logicals.

    The writeln method is the same as the write method, except the writeln method appends a newline character to the end of the output. htm ignores the newline character, except within certain tags such as

    .
    
    

    Use the writeln method within any <script> tag or within an event handler. Event handlers execute after the original document closes, so the writeln method will implicitly open a new document of mimeType text/htm if you do not explicitly issue a document.open() method in the event handler.

    例子

    All the 例子 used for the write method are also valid with the writeln method.

    相关

  • close, clear, open, write methods