分享
 
 
 

javascript手冊-m&n

王朝html/css/js·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

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.

语法

To use a Math object: 1. 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 don't 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. Built-in objects do not have event handlers.

例子

See the 例子 for the individual properties and methods.

max method

Returns the greater of two numbers.

语法Math.max(number1, number2)

number1 and number2 are any numeric arguments or the properties of existing objects.

Method of

Math

例子//Displays the value 20

document.write("The maximum value is " + Math.max(10,20))

//Displays the value -10

document.write("<P>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.

语法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 <FORM> 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.

例子

The following function returns the value of the musicForm method property: function getMethod() {

return document.musicForm.method

}

相关

action, encoding, target properties

min method

Returns the lesser of two numbers.

语法Math.min(number1, number2)

number1 and number2 are any numeric arguments or the properties of existing objects.

Method of

Math

例子//Displays the value 10

document.write("The minimum value is " + Math.min(10,20))

//Displays the value -20

document.write("<P>The minimum value is " + Math.min(-10,-20))

相关

max method

name property

A string specifying the name of an object.

语法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 语法. The name property represents the value of the windowName argument described in the window object 语法. Both forms of the 语法 represent the same value.

name is a read-only property.

All other objects

The name property for all objects except window is represented by forms 1 through 5 of the 语法. 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 object. The value property specifies the label for these objects. The name property is not displayed onscreen; it is used to reference the objects programatically.

For a select object, the values specified by form 1 and form 5 of the 语法 are the same. For a frame object, the values specified by forms 1, 2, and 3 of the 语法 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 an individual form object. 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.

例子

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 < newWindow.document.valueTest.elements.length; i++) {

msgWindow.document.write(newWindow.document.valueTest.elements[i].name + "<BR>")

}

}

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)

相关

For button, reset, and submit:

value property

navigator object

Contains information about the version of Navigator in use.

语法

To use a navigator object: navigator.propertyName

propertyName 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.

例子

See the 例子 for the individual properties.

相关

link object

anchors object

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有