分享
 
 
 

javascript手冊-s2

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

setTime method

Sets the value of a date object.

语法

dateObjectName.setTime(timevalue)

dateObjectName is either the name of a date object or a property of an existing object.

timevalue is an integer or a property of an existing object, representing the number of milliseconds since the epoch (1 January 1970 00:00:00).

方法

Date

描述

Use the setTime method to help assign a date and time to another date object.

例子theBigDay = new Date("July 1, 1999")

sameAsBigDay = new Date()

sameAsBigDay.setTime(theBigDay.getTime())

相关

getTime method

setTimeout method

Evaluates an expression after a specified number of milliseconds have elapsed.

语法timeoutID=setTimeout(expression, msec)

timeoutID is an identifier that is used only to cancel the evaluation with the clearTimeout method.

expression is a string expression or a property of an existing object.

msec is a numeric value, numeric string, or a property of an existing object in millisecond units.

方法

frame, window

描述

The setTimeout method evaluates an expression after a specified amount of time. It does not evaluate the expression repeatedly. For example, if a setTimeout method specifies 5 seconds, the expression is evaluated after 5 seconds, not every 5 seconds.

例子

Example 1. The following example displays an alert message 5 seconds (5,000 milliseconds) after the user clicks a button. If the user clicks the second button before the alert message is displayed, the timeout is canceled and the alert does not display.

Click the button on the left for a reminder in 5 seconds;

click the button on the right to cancel the reminder before

it is displayed.

Example 2. The following example displays the current time in a text object. The showtime() function, which is called recursively, uses the setTimeout method update the time every second.

相关

clearTimeout method

setYear method

Sets the year for a specified date.

语法dateObjectName.setYear(yearValue)

dateObjectName is either the name of a date object or a property of an existing object.

yearValue is an integer greater than 1900 or a property of an existing object.

方法

Date

例子theBigDay.setYear(96)

相关

getYear method

sin method

Returns the sine of a number.

语法Math.sin(number)

number is a numeric expression or a property of an existing object, representing the size of an angle in radians.

方法

Math

描述

The sin method returns a numeric value between -1 and 1, which represents the sine of the angle.

例子//Displays the value 1

document.write("The sine of pi/2 radians is " +

Math.sin(Math.PI/2))

//Displays the value 1.224606353822377e-016

document.write("<P>The sine of pi radians is " +

Math.sin(Math.PI))

//Displays the value 0

document.write("<P>The sine of 0 radians is " +

Math.sin(0))

相关

acos, asin, atan, cos, tan methods

small method

Causes a string to be displayed in a small font as if it were in a <SMALL> tag.

语法stringName.small()

stringName is any string or a property of an existing object.

方法

string

描述

Use the small method with the write or writeln methods to format and display a string in a document.

例子The following example uses string methods to change the size of a string: var worldString="Hello, world"

document.write(worldString.small())

document.write("<P>" + worldString.big())

document.write("<P>" + worldString.fontsize(7))

The previous example produces the same output as the following htm: <SMALL>Hello, world</SMALL>

<P><BIG>Hello, world</BIG>

<P><FONTSIZE=7>Hello, world</FONTSIZE>

相关

big, fontsize methods

sqrt method

Returns the square root of a number.

语法Math.sqrt(number)

number is any non-negative numeric expression or a property of an existing object.

方法

Math

描述

If the value of number is outside the suggested range, the return value is always 0.

例子//Displays the value 3

document.write("The square root of 9 is " + Math.sqrt(9))

//Displays the value 1.414213562373095

document.write("<P>The square root of 2 is " + Math.sqrt(2))

//Displays the value 0 because the argument is out of range

document.write("<P>The square root of -1 is " + Math.sqrt(-1))

SQRT1_2 property

The square root of one-half; equivalently, one over the square root of two, approximately 0.707.

语法Math.SQRT1_2

Property of

Math

描述

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

例子

The following example displays 1 over the square root of 2: document.write("1 over the square root of 2 is " + Math.SQRT1_2)

相关

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

SQRT2 property

The square root of two, approximately 1.414.

语法Math.SQRT2

Property of

Math

描述

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

例子

The following example displays the square root of 2: document.write("The square root of 2 is " + Math.SQRT2)

相关

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

status property

Specifies a priority or transient message in the status bar at the bottom of the window, such as the message that appears when a mouseOver event occurs over an anchor.

语法windowReference.status

windowReference is a valid way of referring to a window, as described in the window object.

Property of

window

描述

Do not confuse the status property with the defaultStatus property. The defaultStatus property reflects the default message displayed in the status bar.

You can set the status property at any time. You must return true if you want to set the status property in the onMouseOver event handler.

例子

Suppose you have created a JavaScript function called pickRandomURL() that lets you select a URL at random. You can use the onClick event handler of an anchor to specify a value for the HREF attribute of the anchor dynamically, and the onMouseOver event handler to specify a custom message for the window in the status property: Go!

In the above example, the status property of the window is assigned to the window's self property, as self.status. As this example shows, you must return true to set the status property in the onMouseOver event handler.

相关

defaultStatus property

strike method

Causes a string to be displayed as struck out text as if it were in a <STRIKE> tag.

语法stringName.strike()

stringName is any string or a property of an existing object.

方法

string

描述

Use the strike method with the write or writeln methods to format and display a string in a document.

例子The following example uses string methods to change the formatting of a string: var worldString="Hello, world"

document.write(worldString.blink())

document.write("<P>" + worldString.bold())

document.write("<P>" + worldString.italics())

document.write("<P>" + worldString.strike())

The previous example produces the same output as the following htm: <BLINK>Hello, world</BLINK>

<P><B>Hello, world</B>

<P><I>Hello, world</I>

<P><STRIKE>Hello, world</STRIKE>

相关

blink, bold, italics methods

string object

A series of characters.

语法

To use a string object: 1. stringName.propertyName

2. stringName.methodName(parameters)

stringName is the name of a string variable.

propertyName is one of the properties listed below.

methodName is one of the methods listed below.

Property of

None.

描述

The string object is a built-in JavaScript object.

A string can be represented as a literal enclosed by single or double quotes; for example, "Netscape" or 'Netscape'.

Properties

length reflects the length of the string

Methods

anchor

big

blink

bold

charAt

fixed

fontcolor

fontsize

indexOf

italics

lastIndexOf

link

small

strike

sub

substring

sup

toLowerCase

toUpperCase

Event handlers

None. Built-in objects do not have event handlers.

例子

The following statement creates a string variable. var last_name = "Schaefer"

The following statements evaluate to 8, "SCHAEFER", and "schaefer": last_name.length

last_name.toUpperCase()

last_name.toLowerCase()

相关

text and textarea objects

sub method

Causes a string to be displayed as a subscript as if it were in a <SUB> tag.

语法stringName.sub()

stringName is any string or a property of an existing object.

方法

string

描述

Use the sub method with the write or writeln methods to format and display a string in a document.

例子The following example uses the sub and sup methods to format a string: var superText="superscript"

var subText="subscript"

document.write("This is what a " + superText.sup() + " looks like.")

document.write("<P>This is what a " + subText.sub() + " looks like.")

The previous example produces the same output as the following htm: This is what a <SUP>superscript</SUP> looks like.

<P>This is what a <SUB>subscript</SUB> looks like.

相关

sup method

submit method

Submits a form.

语法formName.submit()

formName is the name of any form or an element in the forms array.

方法

form

描述

The submit method submits the specified form. It performs the same action as a submit button.

Use the submit method to send data back to an http server. The submit method returns the data using either "get" or "post", as specified in the method property.

例子

The following example submits a form called musicChoice: document.musicChoice.submit()

If musicChoice is the first form created, you also can submit it as follows: document.forms[0].submit()

相关 the example for the form object.

相关

submit object

onSubmit event handler

submit object

A submit button on an htm form. A submit button causes a form to be submitted.

语法

To define a submit button, use standard htm 语法 with the addition of the onClick event handler: <INPUT

TYPE="submit"

NAME="submitName"

VALUE="buttonText"

[onClick="handlerText"]>

NAME="submitName" specifies the name of the submit object. You can access this value using the name property.

VALUE="buttonText" specifies the label to display on the button face. You can access this value using the value property.

To use a submit object's properties and methods: 1. submitName.propertyName

2. submitName.methodName(parameters)

3. formName.elements[index].propertyName

4. formName.elements[index].methodName(parameters)

submitName is the value of the NAME attribute of a submit 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 submit object on a form.

propertyName is one of the properties listed below.

methodName is one of the methods listed below.

Property of

form

描述

A submit object on a form looks as follows:

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

Clicking a submit button submits a form to the URL specified by the form's action property. This action always loads a new page into the client; it may be the same as the current page, if the action so specifies or is not specified.

The submit button's onClick event handler cannot prevent a form from being submitted; instead, use the form's onSubmit event handler or use the submit method instead of a submit object. See the 例子 for the form object.

Properties

name reflects the NAME attribute

value reflects the VALUE attribute

Methods

click

Event handlers

onClick

例子

The following example creates a submit object called submit_button. The text "Done" is displayed on the face of the button.

相关 the 例子 for the form object.

相关

button, form, and reset objects

submit method

onSubmit event handler

substring method

Returns a subset of a string object.

语法stringName.substring(indexA, indexB)

stringName is any string or a property of an existing object.

indexA is any integer from 0 to stringName.length - 1, or a property of an existing object.

indexB is any integer from 0 to stringName.length - 1, or a property of an existing object.

方法

string

描述

Characters in a string are indexed from left to right. The index of the first character is 0, and the index of the last character is stringName.length - 1.

If indexA is less than indexB, the substring method returns the subset starting with the character at indexA and ending with the character before indexB. If indexA is greater than indexB, the substring method returns the subset starting with the character at indexB and ending with the character before indexA. If indexA is equal to indexB, the substring method returns the empty string.

例子The following example uses substring to display characters from the string "Netscape". var anyString="Netscape"

//Displays "Net"

document.write(anyString.substring(0,3))

document.write(anyString.substring(3,0))

//Displays "cap"

document.write(anyString.substring(4,7))

document.write(anyString.substring(7,4))

sup method

Causes a string to be displayed as a superscript as if it were in a <SUP> tag.

语法stringName.sup()

stringName is any string or a property of an existing object.

方法

string

描述

Use the sup method with the write or writeln methods to format and display a string in a document.

例子The following example uses the sub and sup methods to format a string: var superText="superscript"

var subText="subscript"

document.write("This is what a " + superText.sup() + " looks like.")

document.write("<P>This is what a " + subText.sub() + " looks like.")

The previous example produces the same output as the following htm: This is what a <SUP>superscript</SUP> looks like.

<P>This is what a <SUB>subscript</SUB> looks like.

相关

sub method

Last modified 01/01/1998 23:55:24

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
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- 王朝網路 版權所有