分享
 
 
 

javascript手冊-c

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

ceil method

Returns the least integer greater than or equal to a number.

语法Math.ceil(number)

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

用法

Math

例子//Displays the value 46

document.write("The ceil of 45.95 is " + Math.ceil(45.95))

//Displays the value -45

document.write("<P>The ceil of -45.95 is " + Math.ceil(-45.95))

See also

floor method

charAt method

Returns the character at the specified index.

语法stringName.charAt(index)

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

index 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 the index you supply is out of range, JavaScript returns an empty string.

例子The following example displays characters at different locations in the string "Brave new world". var anyString="Brave new world"

document.write("The character at index 0 is " + anyString.charAt(0))

document.write("The character at index 1 is " + anyString.charAt(1))

document.write("The character at index 2 is " + anyString.charAt(2))

document.write("The character at index 3 is " + anyString.charAt(3))

document.write("The character at index 4 is " + anyString.charAt(4))

See also

indexOf, lastIndexOf methods

checkbox object

A checkbox on an htm form. A checkbox is a toggle switch that lets the user set a value on or off.

语法

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

TYPE="checkbox"

NAME="checkboxName"

VALUE="checkboxValue"

[CHECKED]

[onClick="handlerText"]>

textToDisplay

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

VALUE="checkboxValue" specifies a value that is returned to the server when the checkbox is selected and the form is submitted. This defaults to "on". You can access this value using the value property.

CHECKED specifies that the checkbox is displayed as checked. You can access this value using the defaultChecked property.

textToDisplay specifies the label to display beside the checkbox.

To use a checkbox object's properties and methods: 1. checkboxName.propertyName

2. checkboxName.methodName(parameters)

3. formName.elements[index].propertyName

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

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

propertyName is one of the properties listed below.

methodName is one of the methods listed below.

Property of

form

描述

A checkbox object on a form looks as follows:

Overnight delivery

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

Use the checked property to specify whether the checkbox is currently checked. Use the defaultChecked property to specify whether the checkbox is checked when the form is loaded.

Properties

checked lets you programatically check a checkbox

defaultChecked reflects the CHECKED attribute

name reflects the NAME attribute

value reflects the VALUE attribute

Methods

click

Event handlers

onClick

例子

Example 1. The following example displays a group of four checkboxes that all appear checked by default. Specify your music preferences (check all that apply):

R&B

Jazz

Blues

New Age

Example 2. The following example contains a form with three text boxes and one checkbox. The checkbox lets the user choose whether the text fields are converted to upper case. Each text field has an onChange event handler that converts the field value to upper case if the checkbox is checked. The checkbox has an onClick event handler that converts all fields to upper case when the user checks the checkbox.

Checkbox object example

Last name:

First name:

City:

Convert fields to upper case

See also

form and radio objects

checked property

A Boolean value specifying the selection state of a checkbox object or radio button.

语法1. checkboxName.checked

2. radioName[index].checked

checkboxName is either the value of the NAME attribute of a checkbox object or an element in the elements array.

radioName is the value of the NAME attribute of a radio object.

index is an integer representing a radio button in a radio object.

Property of

checkbox, radio

描述

If a checkbox or radio button is selected, the value of its checked property is true; otherwise, it is false.

You can set the checked property at any time. The display of the checkbox or radio button updates immediately when you set the checked property.

例子

The following example examines an array of radio buttons called musicType on the musicForm form to determine which button is selected. The VALUE attribute of the selected button is assigned to the checkedButton variable. function stateChecker() {

var checkedButton = ""

for (var i in document.musicForm.musicType) {

if (document.musicForm.musicType[i].checked=="1") {

checkedButton=document.musicForm.musicType[i].value

}

}

}

See also

defaultChecked property

clear method

Clears the document in a window.

语法document.clear()

用法

document

描述

The clear method empties the content of a window, regardless of how the content of the window has been painted.

例子

When the following function is called, the clear method empties the contents of the msgWindow window: function windowCleaner() {

msgWindow.document.clear()

msgWindow.document.close()

}

See also

close, open, write, writeln methods

clearTimeout method

Cancels a timeout that was set with the setTimeout method.

语法clearTimeout(timeoutID)

timeoutID is a timeout setting that was returned by a previous call to the setTimeout method.

用法

frame, window

描述

See the 描述 for the setTimeout method.

例子

See the 例子 for the setTimeout method.

See also

setTimeout method

click method

Simulates a mouse click on the calling form element.

语法1. buttonName.click()

2. radioName[index].click()

3. checkboxName.click()

buttonName is either the value of the NAME attribute of a button, reset, or submit object or an element in the elements array.

radioName is the value of the NAME attribute of a radio object or an element in the elements array.

index is an integer representing a radio button in a radio object.

checkboxName is either the value of the NAME attribute of a checkbox object or an element in the elements array.

用法

button, checkbox, radio, reset, submit

描述

The effect of the click method varies according to the calling element:

For button, reset, and submit, performs the same action as clicking the button.

For a radio, selects a radio button.

For a checkbox, checks the checkbox and sets its value to on.

例子

The following example toggles the selection status of the first radio button in the musicType radio object on the musicForm form: document.musicForm.musicType[0].click()

The following example toggles the selection status of the newAge checkbox on the musicForm form: document.musicForm.newAge.click()

close method (document object)

Closes an output stream and forces data sent to layout to display.

语法document.close()

用法

document

描述

The close method closes a stream opened with the document.open() method. If the stream was opened to layout, the close method forces the content of the stream to display. Font style tags, such as <BIG> and <CENTER>, automatically flush a layout stream.

The close method also stops the "meteor shower" in the Netscape icon and displays "Document: Done" in the status bar.

例子The following function calls document.close() to close a stream that was opened with document.open(). The document.close() method forces the content of the stream to display in the window. function windowWriter1() {

var myString = "Hello, world!"

msgWindow.document.open()

msgWindow.document.write(myString + "<P>")

msgWindow.document.close()

}

See also

clear, open, write, writeln methods

close method (window object)

Closes the specified window.

语法windowReference.close()

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

用法

window

描述

The close method closes the specified window. If you call close without specifying a windowReference, JavaScript closes the current window.

In event handlers, you must specify window.close() instead of simply using close(). Due to the scoping of static objects in JavaScript, a call to close() without specifying an object name is equivalent to document.close().

例子

Any of the following 例子 close the current window: window.close()

self.close()

close()

The following example closes the messageWin window: messageWin.close()

This example assumes that the window was opened in a manner similar to the following: messageWin=window.open("")

See also

open method

confirm method

Displays a Confirm dialog box with the specified message and OK and Cancel buttons.

语法

confirm("message")

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

用法

window

描述

Use the confirm method to ask the user to make a decision that requires either an OK or a Cancel. The message argument specifies a message that prompts the user for the decision. The confirm method returns true if the user chooses OK and false if the user chooses Cancel.

Although confirm is a 用法 the window object, you do not need to specify a windowReference when you call it. For example, windowReference.confirm() is unnecessary.

例子

This example uses the confirm method in the confirmCleanUp() function to confirm that the user of an application really wants to quit. If the user chooses OK, the custom cleanUp() function closes the application. function confirmCleanUp() {

if (confirm("Are you sure you want to quit this application?")) {

cleanUp()

}

}

You can call the confirmCleanUp() function in the onClick event handler of a form's pushbutton, as shown in the following example: <INPUT TYPE="button" VALUE="Quit" onClick="confirmCleanUp()">

See also

alert, prompt methods

cookie property

String value of a cookie, which is a small piece of information stored by the Navigator in the cookies.txt file.

语法document.cookie

Property of

document

描述

Use string methods such as substring, charAt, indexOf, and lastIndexOf to determine the value stored in the cookie. See the Netscape cookie specification for a complete specification of the cookie 语法.

You can set the cookie property at any time.

例子

The following function uses the cookie property to record a reminder for users of an application. The "expires=" component sets an expiration date for the cookie, so it persists beyond the current browser session. The format of the date must be Wdy, DD-Mon-YY HH:MM:SS GMT

where Wdy is the full name of the day of the week, DD is an integer representation of the day of the month, Mon is the month, YY is the last two digits of the year, and HH, MM, and SS are two-digit representations of hours, minutes, and seconds, respectively.

This is the same date format as returned by Date.toGMTString, except:

Dashes are added between the day, month, and year

Year is two-digit for cookies.

For example, a valid cookie expiration date is:

expires=Wednesday, 09-Nov-99 23:12:40 GMT function RecordReminder(time, expression) {

// Record a cookie of the form "@=" to map

// from in milliseconds since the epoch,

// returned by Date.getTime(), onto an encoded expression,

// (encoded to contain no white space, semicolon,

// or comma characters)

document.cookie = "@" + time + "=" + expression + ";"

// set the cookie expiration time to one day

// beyond the reminder time

document.cookie += "expires=" + cookieDate(time + 24*60*60*1000)

// cookieDate is a function that formats the date according to the cookie spec

}

When the user loads the page that contains this function, another function uses indexOf("@") and indexOf("=") to determine the date and time stored in the cookie.

See also

hidden object

cos method

Returns the cosine of a number.

语法Math.cos(number)

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

用法

Math

描述

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

例子//Displays the value 6.123031769111886e-017

document.write("The cosine of PI/2 radians is " + Math.cos(Math.PI/2))

//Displays the value -1

document.write("<P>The cosine of PI radians is " + Math.cos(Math.PI))

//Displays the value 1

document.write("<P>The cosine of 0 radians is " + Math.cos(0))

See also

acos, asin, atan, sin, tan methods

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