# javascript手冊-p&q

## parent property

The parent property is a synonym for a window or frame whose frameset contains the current frame.

### 语法

1. parent.propertyName
2. parent.methodName
3. parent.frameName
4. parent.frames[index]


propertyName is the defaultStatus, status, length, name, or parent property when the calling parent refers to a window object.
propertyName is the length, name, or parent property when the calling parent refers to a frame object.
methodName is any method associated with the window object.
frameName and frames[index] are ways to refer to frames.

### Description

The parent property refers to the <FRAMESET> window of a frame. Child frames within a frameset refer to sibling frames by using "parent" in place of the window name as follows: parent.frameName or parent.frames[index]. For example, if the fourth frame in a set has NAME="homeFrame", sibling frames can refer to that frame using parent.homeFrame or parent.frames[3].

You can use parent.parent to refer to the "grandparent" frame or window when a <FRAMESET> tag is nested within a child frame.

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

     <object nameAttribute>
where nameAttribute is the NAME attribute if the parent is a frame, or an internal reference if the parent is a window.

### 例子

See the 例子 for the frame object.

## parse method

Returns the number of milliseconds in a date string since January 1, 1970 00:00:00, local time.

### 语法

Date.parse(dateString)
dateString is a string representing a date or a property of an existing object.

### Description

The parse method takes a date string (such as "Dec 25, 1995"), and returns the number of milliseconds since January 1, 1970 00:00:00 (local time). This function is useful for setting date values based on string values, for example in conjunction with the setTime method and the Date object.

Given a string representing a time, parse returns the time value. It accepts the IETF standard date 语法: "Mon, 25 Dec 1995 13:30:00 GMT". It understands the continental US time zone abbreviations, but for general use, use a time zone offset, for example "Mon, 25 Dec 1995 13:30:00 GMT+0430" (4 hours, 30 minutes west of the Greenwich meridian). If you do not specify a time zone, the local time zone is assumed. GMT and UTC are considered equivalent.

Because the parse function is a static method of Date, you always use it as Date.parse(), rather than as a method of a date object you created.

### 例子

If IPOdate is an existing date object, then

IPOdate.setTime(Date.parse("Aug 9, 1995"))


UTC method

## parseFloat function

Parses a string argument and returns a floating point number.

### 语法

parseFloat(string)

string is a string that represents the value you want to parse.

### Description

The parseFloat function is a built-in JavaScript function. It is not a method associated with any object, but is part of the language itself.

parseFloat parses its argument, a string, and returns a floating point number. If it encounters a character other than a sign ( + or -), numeral (0-9), a decimal point, or an exponent, then it returns the value up to that point and ignores that character and all succeeding characters.

If the first character cannot be converted to a number, parseFloat returns one of the following values:

0 on Windows platforms. "NaN" on any other platform, indicating that the value is not a number.

For arithmetic purposes, the "NaN" value is not a number in any radix. You can call the isNaN function to determine if the result of parseFloat is "NaN". If "NaN" is passed on to arithmetic operations, the operation results will also be "NaN".

### 例子

The following 例子 all return 3.14:

parseFloat("3.14")
parseFloat("314e-2")
parseFloat("0.0314E+2")
var x = "3.14"
parseFloat(x)


The following example returns "NaN" or 0:

parseFloat("FF2")


### 相关

isNaN, parseInt functions

## parseInt function

Parses a string argument and returns an integer of the specified radix or base.

### 语法

parseInt(string [,radix])

string is a string that represents the value you want to parse.
radix is an integer that represents the radix of the return value.

### Description

The parseInt function is a built-in JavaScript function. It is not a method associated with any object, but is part of the language itself.

The parseInt function parses its first argument, a string, and attempts to return an integer of the specified radix (base). For example, a radix of 10 indicates to convert to a decimal number, 8 octal, 16 hexadecimal, and so on. For radixes above 10, the letters of the alphabet indicate numerals greater than 9. For example, for hexadecimal numbers (base 16), A through F are used.

If parseInt encounters a character that is not a numeral in the specified radix, it ignores it and all succeeding characters and returns the integer value parsed up to that point. ParseInt truncates numbers to integer values.

If the radix is not specified or is specified as 0, JavaScript assumes the following:

If the input string begins with "0x", the radix is 16 (hexadecimal). If the input string begins with "0", the radix is 8 (octal). If the input string begins with any other value, the radix is 10 (decimal).

If the first character cannot be converted to a number, parseFloat returns one of the following values:

0 on Windows platforms. "NaN" on any other platform, indicating that the value is not a number.

For arithmetic purposes, the "NaN" value is not a number in any radix. You can call the isNaN function to determine if the result of parseInt is "NaN". If "NaN" is passed on to arithmetic operations, the operation results will also be "NaN".

### 例子

The following 例子 all return 15:

parseInt("F", 16)
parseInt("17", 8)
parseInt("15", 10)
parseInt(15.99, 10)
parseInt("FXX123", 16)
parseInt("1111", 2)
parseInt("15*3", 10)


The following 例子 all return "NaN" or 0:

parseInt("Hello", 8)
parseInt("0x7", 10)
parseInt("FFF", 10)


Even though the radix is specified differently, the following 例子 all return 17 because the input string begins with "0x".

parseInt("0x11", 16)
parseInt("0x11", 0)
parseInt("0x11")


### 相关

isNaN, parseFloat functions

A text field on an htm form that conceals its value by displaying asterisks (*). When the user enters text into the field, asterisks (*) hide anything entered from view.

### 语法

To define a password object, use standard htm 语法:

<INPUT
[VALUE="textValue"]
SIZE=integer>

NAME="passwordName" specifies the name of the password object. You can access this value using the name property.
VALUE="textValue" specifies the initial value of the password object. You can access this value using the defaultValue property.
SIZE=integer specifies the number of characters the password object can accommodate without scrolling.

To use a password object's properties and methods:

1. passwordName.propertyName
3. formName.elements[index].propertyName
4. formName.elements[index].methodName(parameters)

passwordName is the value of the NAME attribute of a password object.
formName is either the value of the NAME attribute of a form object or an element in the forms array.
index is an integer representing a password object on a form.
propertyName is one of the properties listed below.
methodName is one of the methods listed below.

form

### Description

A password object on a form looks as follows:

A password object is a form element and must be defined within a <FORM> tag.

### Properties

defaultValue reflects the VALUE attribute name reflects the NAME attribute value reflects the current value of the password object's field

### Methods

focus blur select

None.

### 相关

form and text objects

## pathname property

A string specifying the url-path portion of the URL.

### 语法

1. links[index].pathname
2. location.pathname


index is an integer representing a link object.

### Description

The pathname property specifies a portion of the URL. The pathname supplies the details of how the specified resource can be accessed.

You can set the pathname property at any time, although it is safer to set the href property to change a location. If the pathname that you specify cannot be found in the current location, you will get an error.

See Section 3.1 of RFC 1738 for complete information about the pathname.

### 例子

See the 例子 for the href property.

### 相关

hash, host, hostname, href, port, protocol, search properties

## PI property

The ratio of the circumference of a circle to its diameter, approximately 3.14159.

### 语法

Math.PI

### Description

Because PI is a constant, it is a read-only property of Math.

### 例子

The following example displays the value of pi:

document.write("The value of pi is " + Math.PI)

### 相关

E, LN2, LN10, LOG2E, LOG10E, SQRT1_2, SQRT2 properties

## port property

A string specifying the communications port that the server uses for communications.

### 语法

1. links[index].port
2. location.port


index is an integer representing a link object.

### Description

The port property specifies a portion of the URL. The port property is a substring of the host property. The host property is the concatenation of the hostname and port properties, separated by a colon. When the port property is not defined, the host property is the same as the hostname property.

You can set the port property at any time, although it is safer to set the href property to change a location. If the port that you specify cannot be found in the current location, you will get an error. If the port property is not specified, it defaults to 80 on the server.

See Section 3.1 of RFC 1738 for complete information about the port.

### 例子

See the 例子 for the href property.

### 相关

hash, host, hostname, href, pathname, protocol, search properties

## pow method

Returns base to the exponent power, that is, baseexponent.

### 语法

Math.pow(base, exponent)
base is any numeric expression or a property of an existing object.
exponent is any numeric expression or a property of an existing object. If the result would include an imaginary number (for example pow(-1, 0.5)), then the value returned is always zero.

### 例子

//Displays the value 49
document.write("7 to the power of 2 is " + Math.pow(7,2))

//Displays the value 1024
document.write("<P>2 to the power of 10 is " + Math.pow(2,10))


exp, log methods

## prompt method

Displays a Prompt dialog box with a message and an input field.

### 语法

prompt(message, [inputDefault])
message is any string or a property of an existing object; the string is displayed as the message.
inputDefault is a string, integer, or property of an existing object that represents the default value of the input field.

### Description

Use the prompt method to display a dialog box that receives user input. If you do not specify an initial value for inputDefault, the dialog box displays the value <undefined>.

Although prompt is a method of the window object, you do not need to specify a windowReference when you call it. For example, windowReference.prompt() is unnecessary.

### 例子

prompt("Enter the number of cookies you want to order:", 12)


## protocol property

A string specifying the beginning of the URL, up to and including the first colon.

### 语法

1. links[index].protocol
2. location.protocol


index is an integer representing a link object.

### Description

The protocol property specifies a portion of the URL. The protocol indicates the access method of the URL. For example, a protocol of "http:" specifies Hypertext Transfer Protocol, and a protocol of "javascript:" specifies JavaScript code.

You can set the protocol property at any time, although it is safer to set the href property to change a location. If the protocol that you specify cannot be found in the current location, you will get an error.

The protocol property represents the scheme name of the URL. See Section 2.1 of RFC 1738 for complete information about the protocol.

### 例子

See the 例子 for the href property.

### 相关

hash, host, hostname, href, pathname, port, search properties
• 本文已收录于以下专栏：

举报原因： 您举报文章：javascript手冊-p&q 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)