Links and Anchors: Window 2
2007-11-27 17:53:33 来源:WEB开发网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 0document.write(The arc cosine of 1 is + Math.acos(1))// Displays the value 3.141592653589793document.write(<P>The arc cosine of -1 is + Math.acos(-1))// Displays the value 0document.write(<P>The arc cosine of 2 is + Math.acos(2))
See also
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
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 forms text object, as shown in the following example:
Name: <INPUT TYPE=text NAME=userName onBlur=testValue(userName.value)>
See also
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
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:
The previous example produces the same output as the following htm:
See also
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
描述
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:
Methods
Event handlers
例子
Example 1: an anchor. The following example defines an anchor for the text Welcome to JavaScript.
Welcome to JavaScript
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:
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:
LINK2.htm, which contains the anchors, contains the following code:
Some colors (Anchor 1)
Some music types (Anchor 2)
Some countries (Anchor 3)
See also
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 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 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:
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, its set to \n, which is the newline character for Unix and Macintosh.
- ››Android 当修改一些代码时,使用什么编译命令可以最...
- ››Android 如何添加一个apk使模拟器和真机都编译进去...
- ››Android 修改Camera拍照的默认保存路径
- ››Android 如何修改默认输入法
- ››android开发中finish()和System.exit(0)的区别
- ››Android手势识别简单封装类
- ››android中查看项目数字证书的两种方法
- ››Android中获取IMEI码的办法
- ››android 相机报错 setParameters failed
- ››Android重启运用程序的代码
- ››Android为ListView的Item设置不同的布局
- ››android bitmap与base64字符串的互相转换
更多精彩
赞助商链接