当前页面: 开发资料首页 → Javascript 专题 → javascript手冊-a
摘要: javascript
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>Enter a number: <input TYPE="text" NAME="absEntry">
The absolute value is: <input TYPE="text" NAME="result">
<input TYPE="button" VALUE="Calculate" onClick="form.result.value = Math.abs(form.absEntry.value)"> </form>
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("The arc cosine of -1 is " + Math.acos(-1)) // Displays the value 0 document.write("
The arc cosine of 2 is " + Math.acos(2))
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.
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
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)">
A string specifying the color of an active link (after mouse-button down, but before mouse-button up).
document.alinkColor
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"
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.