CSDN博客

img longj

javascript手冊-a

发表于2001/8/27 19:48:00  487人阅读

abs method

Returns the absolute value of a number.

语法

Math.abs(number)

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

用法

Math

例子

In the following example, the user enters a number in the first text box and presses the Calculate button to display the absolute value of the number.

<FORM>
<P>Enter a number:
<INPUT TYPE="text" NAME="absEntry">

<P>The absolute value is:
<INPUT TYPE="text" NAME="result">

<P>
<INPUT TYPE="button" VALUE="Calculate"
   onClick="form.result.value = Math.abs(form.absEntry.value)">

</FORM>

acos method

Returns the arc cosine (in radians) of a number.

语法

Math.acos(number)

number is a numeric expression between -1 and 1, or a property of an existing object.

用法

Math

描述

The acos method returns a numeric value between 0 and pi radians. If the value of number is outside the suggested range, the return value is always 0.

例子

// Displays the value 0
document.write("The arc cosine of 1 is " + Math.acos(1))

// Displays the value 3.141592653589793
document.write("<P>The arc cosine of -1 is " + Math.acos(-1))

// Displays the value 0
document.write("<P>The arc cosine of 2 is " + Math.acos(2))

See also

  • asin, atan, cos, sin, tan methods

    action property

    A string specifying a destination URL for form data that is submitted.

    语法

    formName.action

    formName is either the name of a form or an element in the forms array.

    Property of

    form

    描述

    The action property is a reflection of the ACTION attribute of the <FORM> tag. Each section of a URL contains different information. See the location object for a 描述 of the URL components.

    You can set the action property at any time.

    Certain values of the action property may require specific values for other form properties. See RFC 1867 for more information.

    例子

    The following example sets the action property of the musicForm form to the value of the variable urlName:

    document.musicForm.action=urlName

    See also

  • encoding, method, target properties

    alert method

    Displays an Alert dialog box with a message and an OK button.

    语法

    alert("message")

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

    用法

    window

    描述

    Use the alert method to display a message that does not require a user decision. The message argument specifies a message that the dialog box contains.

    Although alert is a 用法 the window object, you do not need to specify a windowReference when you call it. For example, windowReference.alert() is unnecessary.

    例子

    In the following example, the testValue() function checks the name entered by a user in the text object of a form to make sure that it is no more than eight characters in length. This example uses the alert method to prompt the user to enter a valid value.

    function testValue(textElement) {
       if (textElement.length > 8) {
          alert("Please enter a name that is 8 characters or less")
       }
    }
    You can call the testValue() function in the onBlur event handler of a form's text object, as shown in the following example:
    Name: <INPUT TYPE="text" NAME="userName"
       onBlur="testValue(userName.value)">

    See also

  • confirm, prompt methods

    alinkColor property

    A string specifying the color of an active link (after mouse-button down, but before mouse-button up).

    语法

    document.alinkColor

    Property of

    document

    描述

    The alinkColor 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 ALINK attribute of the <BODY> tag. 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 active links to aqua using a string literal:

    document.alinkColor="aqua"
    

    The following example sets the color of active links to aqua using a hexadecimal triplet:

    document.alinkColor="00FFFF"
    

    See also

  • bgColor, fgColor, linkColor, and vlinkColor properties

    anchor method

    Creates an htm anchor that is used as a hypertext target.

    语法

    text.anchor(nameAttribute)

    text is any string or a property of an existing object.
    nameAttribute is any string or a property of an existing object.

    用法

    string

    描述

    Use the anchor method with the write or writeln methods to programatically create and display an anchor in a document. Create the anchor with the anchor method, then call write or writeln to display the anchor in a document.

    In the 语法, the text string represents the literal text that you want the user to see. The nameAttribute string represents the NAME attribute of the <A> tag.

    Anchors created with the anchor method become elements in the anchors array. See the anchor object for information about the anchors array.

    例子

    The following example opens the msgWindow window and creates an anchor for the Table of Contents:

    var myString="Table of Contents" msgWindow=window.open("","displayWindow") msgWindow.document.writeln(myString.anchor("contents_anchor")) msgWindow.document.close()

    The previous example produces the same output as the following htm:

    <A NAME="contents_anchor">Table of Contents</A>

    See also

  • link method

    anchor object (anchors array)

    A piece of text that can be the target of a hypertext link.

    语法

    To define an anchor, use standard htm 语法:

    <A [HREF=locationOrURL]
       NAME="anchorName"
       [TARGET="windowName"]>
       anchorText
    </A>
    
    HREF=locationOrURL identifies a destination anchor or URL. If this attribute is present, the anchor object is also a link object. See link for details.
    NAME="anchorName" specifies a tag that becomes an available hypertext target within the current document.
    TARGET="windowName" specifies the window that the link is loaded into. This attribute is meaningful only if HREF=locationOrURL is present. See link for details.
    anchorText specifies the text to display at the anchor.

    You can also define an anchor using the anchor method.

    Property of

  • document

    描述

    If an anchor object is also a link object, the object has entries in both the anchors and links arrays.

    The anchors array

    You can reference the anchor objects in your code by using the anchors array. This array contains an entry for each <A> tag containing a NAME attribute in a document in source order. For example, if a document contains three named anchors, these anchors are reflected as document.anchors[0], document.anchors[1], and document.anchors[2].

    To use the anchors array:

    1. document.anchors[index]
    2. document.anchors.length
    

    index is an integer representing an anchor in a document.

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

    Even though the anchors array represents named anchors, the value of anchors[index] is always null. But if a document names anchors in a systematic way using natural numbers, you can use the anchors array and its length property to validate an anchor name before using it in operations such as setting location.hash. See the example below.

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

    Properties

    The anchors object has no properties. The anchors array has the following properties:

  • length reflects the number of named anchors in a document

    Methods

  • None.

    Event handlers

  • None.

    例子

    Example 1: an anchor. The following example defines an anchor for the text "Welcome to JavaScript".

    <A NAME="javascript_intro"><H2>Welcome to JavaScript</H2></A>

    If the preceding anchor is in a file called intro.htm, a link in another file could define a jump to the anchor as follows:

    <A HREF="tppmsgs/msgs0.htm#8" tppabs="http://www.nease.net/~jim/intro.htm#javascript_intro">Introduction</A>

    Example 2: anchors array. The following example opens two windows. The first window contains a series of buttons that set location.hash in the second window to a specific anchor. The second window defines four anchors named "0", "1", "2", and "3". (The anchor names in the document are therefore 0, 1, 2, ... (document.anchors.length-1)). When a button is pressed in the first window, the onClick event handler verifies that the anchor exists before setting window2.location.hash to the specified anchor name.

    LINK1.htm, which defines the first window and its buttons, contains the following code:

    <htm> <HEAD> <TITLE>Links and Anchors: Window 1</TITLE> </HEAD> <BODY> <SCRIPT> window2=open("link2.htm","secondLinkWindow","scrollbars=yes,width=250, height=400") function linkToWindow(num) { if (window2.document.anchors.length > num) window2.location.hash=num else alert("Anchor does not exist!") } </SCRIPT> <B>Links and Anchors</B> <FORM> <P>Click a button to display that anchor in window #2 <P><INPUT TYPE="button" VALUE="0" NAME="link0_button" onClick="linkToWindow(this.value)"> <INPUT TYPE="button" VALUE="1" NAME="link0_button" onClick="linkToWindow(this.value)"> <INPUT TYPE="button" VALUE="2" NAME="link0_button" onClick="linkToWindow(this.value)"> <INPUT TYPE="button" VALUE="3" NAME="link0_button" onClick="linkToWindow(this.value)"> <INPUT TYPE="button" VALUE="4" NAME="link0_button" onClick="linkToWindow(this.value)"> </FORM> </BODY> </htm>

    LINK2.htm, which contains the anchors, contains the following code:

    <htm> <HEAD> <TITLE>Links and Anchors: Window 2</TITLE> </HEAD> <BODY> <A NAME="0"><B>Some numbers</B> (Anchor 0)</A> <LI>one <LI>two <LI>three <LI>four <LI>five <LI>six <LI>seven <LI>eight <LI>nine <P><A NAME="1"><B>Some colors</B> (Anchor 1)</A> <LI>red <LI>orange <LI>yellow <LI>green <LI>blue <LI>purple <LI>brown <LI>black <P><A NAME="2"><B>Some music types</B> (Anchor 2)</A> <LI>R&B <LI>Jazz <LI>Soul <LI>Reggae <LI>Rock <LI>Country <LI>Classical <LI>Opera <P><A NAME="3"><B>Some countries</B> (Anchor 3)</A> <LI>Afghanistan <LI>Brazil <LI>Canada <LI>Finland <LI>India <LI>Italy <LI>Japan <LI>Kenya <LI>Mexico <LI>Nigeria </BODY> </htm>

    See also

  • link object
  • anchor method

    anchors property

    An array of objects corresponding to named anchors in source order. See anchor object.


    appCodeName property

    A string specifying the code name of the browser.

    语法

    navigator.appCodeName

    Property of

    navigator

    描述

    appCodeName is a read-only property.

    例子

    The following example displays the value of the appCodeName property:

    document.write("The value of navigator.appCodeName is " +
       navigator.appCodeName)

    For Navigator 2.0, this displays the following:

    The value of navigator.appCodeName is Mozilla

    See also

  • appName, appVersion, userAgent properties

    appName property

    A string specifying the name of the browser.

    语法

    navigator.appName

    Property of

    navigator

    描述

    appName is a read-only property.

    例子

    The following example displays the value of the appName property:

    document.write("The value of navigator.appName is " +
       navigator.appName)

    For Navigator 2.0, this displays the following:

    The value of navigator.appName is Netscape

    See also

  • appVersion, appCodeName, userAgent properties

    appVersion property

    A string specifying version information for the Navigator.

    语法

    navigator.appVersion

    Property of

    navigator

    描述

    The appVersion property specifies version information in the following format:

    releaseNumber (platform; country)

    The values contained in this format are the following:

  • releaseNumber is the version number of the Navigator. For example, "2.0b4" specifies Navigator 2.0, beta 4.
  • platform is the platform upon which the Navigator is running. For example, "Win16" specifies a 16-bit version of Windows such as Windows 3.11.
  • country is either "I" for the international release, or "U" for the domestic U.S. release. The domestic release has a stronger encryption feature than the international release.

    appVersion is a read-only property.

    例子

    Example 1. The following example displays version information for the Navigator:

    document.write("The value of navigator.appVersion is " +
       navigator.appVersion)

    For Navigator 2.0 on Windows 95, this displays the following:

    The value of navigator.appVersion is 2.0 (Win95, I)

    Example 2. The following example populates a textarea object with newline characters separating each line. Because the newline character varies from platform to platform, the example tests the appVersion property to determine whether the user is running Windows (appVersion contains "Win" for all versions of Windows). If the user is running Windows, the newline character is set to /r/n; otherwise, it's set to /n, which is the newline character for Unix and Macintosh.

    <SCRIPT> var newline=null function populate(textareaObject){ if (navigator.appVersion.lastIndexOf('Win') != -1) newline="/r/n" else newline="/n" textareaObject.value="line 1" + newline + "line 2" + newline + "line 3" } </SCRIPT> <FORM NAME="form1"> <BR><TEXTAREA NAME="testLines" ROWS=8 COLS=55></TEXTAREA> <P><INPUT TYPE="button" VALUE="Populate the textarea object" onClick="populate(document.form1.testLines)"> </TEXTAREA> </FORM>

    See also

  • appName, appCodeName, userAgent properties

    asin method

    Returns the arc sine (in radians) of a number.

    语法

    Math.asin(number)

    number is a numeric expression between -1 and 1, or a property of an existing object.

    用法

    Math

    描述

    The asin method returns a numeric value between -pi/2 and pi/2 radians. If the value of number is outside the suggested range, the return value is always 0.

    例子

    // Displays the value 1.570796326794897 (pi/2)
    document.write("The arc sine of 1 is " + Math.asin(1))
    
    // Displays the value -1.570796326794897 (-pi/2)
    document.write("<P>The arc sine of -1 is " + Math.asin(-1))
    
    // Displays the value 0 because the argument is out of range
    document.write("<P>The arc sine of 2 is " + Math.asin(2))
    

    See also

  • acos, atan, cos, sin, tan methods

    atan method

    Returns the arc tangent (in radians) of a number.

    语法

    Math.atan(number)

    number is either a numeric expression or a property of an existing object, representing the tangent of an angle.

    用法

    Math

    描述

    The atan method returns a numeric value between -pi/2 and pi/2 radians.

    例子

    // Displays the value 0.7853981633974483
    document.write("The arc tangent of 1 is " + Math.atan(1))
    
    // Displays the value -0.7853981633974483
    document.write("<P>The arc tangent of -1 is " + Math.atan(-1))
    
    // Displays the value 0.4636476090008061
    document.write("<P>The arc tangent of .5 is " + Math.atan(.5))
    

    See also

  • acos, asin, cos, sin, tan methods
  • 0 0

    相关博文

    我的热门文章

    img
    取 消
    img