JavaScript Handbook - M & N

zhaozj2021-02-17  70

Math Object

A Built-IN Object That Has Properties and methods for Mathematical Constants and functions. For Example, The Math Object's Pi Property Has The Value of Pi.

grammar

To Use a Math Object:

Math.propertyName

2. Math.MethodName (Parameters)

PropertyName Is One of the Properties Listed Below.

Methodname is one of the methods listed below.

Property of

None. Description The Math object is a built-in JavaScript object. You reference the constant PI as Math.PI. Constants are defined with the full precision of real numbers in JavaScript. Similarly, you reference Math functions as methods. For example, the sine function is Math.sin (argument), where argument is the argument. It is often convenient to use the with statement when a section of code uses several Math constants and methods, so you do not have to type "Math" repeatedly. For example, with (math) {

a = pi * r * r

Y = r * sin (Theta)

X = r * cos (Theta)

}

Properties E LN2 LN10 LOG2E LOG10E PI SQRT1_2 SQRT2 Methods abs acos asin atan ceil cos exp floor log max min pow random round sin sqrt tan Event handlers None. Objects do not have event handlers Built-in. Examples See the examples for the individual properties and Methods.

max method Returns the greater of two numbers. Syntax Math.max (number1, number2) number1 and number2 are any numeric arguments or the properties of existing objects. Method of Math Examples // Displays the value 20

Document.write ("THE MAXIMUM VALUE IS" Math.max (10, 20))

// displays the value -10

Document.write ("

the maximum value is" math.max (-10, -20)))

Min Method

method property A string specifying how form field input information is sent to the server. Syntax formName.method formName is either the name of a form or an element in the forms array. Property of form Description The method property is a reflection of the METHOD attribute of the

tag. The method property should evaluate to either "get" or "post". You can set the method property at any time. Certain values ​​of the method property may require specific values ​​for other form properties. See RFC 1867 For more information. Example The Following Function Returns The Value of The Musicform Method Property: Function GetMethod () {Return Document.MusicForm.Method

}

Related Action, Encoding, Target Properties

MIN Method Returns The Leesr of Two Numbers. Syntax Math.min (Number1, Number2) Number1 and Number2 Are Any Numeric Arguments or the Properties of Existing Objects. Method of Math Example // Displays The Value 10

Document.write ("THE minimum value is" math.min (10, 20))

// Displays the value -20

Document.write ("

the minimum value is" math.min (-10, -20))))

Related Max Method

Name Property a string specifying the name of an object. Syntax 1. Objectname.name

2. Framereference.name

3. framereference.frames.name

4. Radioname [index] .name

5. Selectname.Options.name

6. WindowReference.name

7. WindowReference.frames.name

objectName is either the value of the NAME attribute of any of the objects listed below or an element in the elements array. frameReference is a valid way of referring to a frame, as described in the frame object. 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. windowReference is a valid way of referring to a window, as described in the window object. Property of button, checkbox, frame, hidden, password, radio, reset, select, submit, text, textarea, window options array Description The value of the name property differs between the window object and other objects. window object The name property for the window object is represented by form 6 and form 7 of the syntax. The name property represents the value of the windowName argument described in the window object syntax. Both forms of the grammar represent the same value. name is a read-only property. All other objects The na me property for all objects except window is represented by forms 1 through 5 of the syntax. For all objects except window, the name property initially reflects the value of the NAME attribute. Changing the name property overrides this setting. You can set the name property at any time. The name property is the same for every radio button in a single radio object. Individual radio buttons are referenced by their position in the radio array. Do not confuse the name property with the label displayed on a button, reset, or Submit objecty;

it is used to reference the objects programatically. For a select object, the values ​​specified by form 1 and form 5 of the syntax are the same. For a frame object, the values ​​specified by forms 1, 2, and 3 of the grammar are the same. If multiple objects on the same form have the same nAME attribute, an array of the given name is created automatically. Each element in the array represents individual form object an. Elements are indexed in source order starting at 0. For example, if two text elements and a textarea element on the same form have their NAME attribute set to "myField", an array with the elements myField [0], myField [1], and myField [2] is created. examples In the following example , the valueGetter () function uses a for loop to iterate over the array of elements on the valueTest form The msgWindow window displays the names of all the elements on the form:. newWindow = window.open ( "http: //www.netscape .com ") Function valuegetter () {

Var msgwindow = window.open ("")

For (var i = 0; i

MsgWindow.Document.write (newwindow.document.valuetest.ements [i] .name "
")

}

}

In the following example, the first statement creates a window called netscapeWin. The second statement displays the value "netscapeHomePage" in the alert dialog box, because "netscapeHomePage" is the value of the windowName argument of netscapeWin. NetscapeWin = window.open ( " http://www.netscape.com "," NetscapeHomePage ")

Alert (NetscapeWin.name)

Related for Button, RESET, AND SUBMIT: VALUE Property

navigator object Contains information about the version of Navigator in use syntax To use a navigator object:. navigator.propertyNamepropertyName is one of the properties listed below Property of None Description Use the navigator object to determine which version of the Navigator your users have... Properties appCodeName specifies the code name of the browser appName specifies the name of the browser appVersion specifies version information for the Navigator userAgent specifies the user-agent header Methods None. Event handlers None. examples See the examples for the individual properties. Related link object anchors Object

转载请注明原文地址:https://www.9cbs.com/read-30715.html

New Post(0)