分享
 
 
 

javascript手冊-o

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

onBlur event handler

A blur event occurs when a select, text, or textarea field on a form loses focus. The onBlur event handler executes JavaScript code when a blur event occurs.

See the relevant objects for the onBlur 语法.

Event Handler of

select, text, textarea

例子

In the following example, userName is a required text field. When a user attempts to leave the field, the onBlur event handler calls the required() function to confirm that userName has a legal value. <INPUT TYPE="text" VALUE="" NAME="userName" onBlur="required(this.value)">

相关

onChange , onFocus event handlers

onChange event handler

A change event occurs when a select, text, or textarea field loses focus and its value has been modified. The onChange event handler executes JavaScript code when a change event occurs.

Use the onChange event handler to validate data after it is modified by a user.

See the relevant objects for the onChange 语法.

Event Handler of

select, text, textarea

例子

In the following example, userName is a text field. When a user attempts to leave the field, the onBlur event handler calls the checkValue() function to confirm that userName has a legal value. <INPUT TYPE="text" VALUE="" NAME="userName" onBlur="checkValue(this.value)">

相关

onBlur , onFocus event handlers

onClick event handler

A click event occurs when an object on a form is clicked. The onClick event handler executes JavaScript code when a click event occurs.

See the relevant objects for the onClick 语法.

Event Handler of

button, checkbox, radio, link, reset, submit

例子

For example, suppose you have created a JavaScript function called compute(). You can execute the compute() function when the user clicks a button by calling the function in the onClick event handler, as follows: <INPUT TYPE="button" VALUE="Calculate" onClick="compute(this.form)">

In the above example, the keyword this refers to the current object; in this case, the Calculate button. The construct this.form refers to the form containing the button.

For another example, 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 a link to specify a value for the HREF attribute of the <A> tag dynamically, as shown in the following example: Go!

In the above example, the onMouseOver event handler specifies a custom message for the Navigator status bar when the user places the mouse pointer over the Go! anchor. As this example shows, you must return true to set the window.status property in the onMouseOver event handler.

onFocus event handler

A focus event occurs when a field receives input focus by tabbing with the keyboard or clicking with the mouse. Selecting within a field results in a select event, not a focus event. The onFocus event handler executes JavaScript code when a focus event occurs.

See the relevant objects for the onFocus 语法.

Event Handler of

select, text, textarea

例子

The following example uses an onFocus handler in the valueField textarea object to call the valueCheck() function. <INPUT TYPE="textarea" VALUE="" NAME="valueField" onFocus="valueCheck()">

相关

onBlur , onChange event handlers

onLoad event handler

A load event occurs when Navigator finishes loading a window or all frames within a <FRAMESET>. The onLoad event handler executes JavaScript code when a load event occurs.

Use the onLoad event handler within either the <BODY> or the <FRAMESET> tag, for example, <BODY onLoad="...">.

In a <FRAMESET> and <FRAME> relationship, an onLoad event within a frame (placed in the <BODY> tag) occurs before an onLoad event within the <FRAMESET> (placed in the <FRAMESET> tag).

Event Handler of

window

例子

In the following example, the onLoad event handler displays a greeting message after a web page is loaded. <BODY onLoad="window.alert("Welcome to the Brave New World home page!")>

相关

onUnload event handler

onMouseOver event handler

A mouseOver event occurs once each time the mouse pointer moves over an object from outside that object. The onMouseOver event handler executes JavaScript code when a mouseOver event occurs.

You must return true within the event handler if you want to set the status or defaultStatus properties with the onMouseOver event handler.

See the relevant objects for the onMouseOver 语法.

Event Handler of

link

例子

By default, the HREF value of an anchor displays in the status bar at the bottom of the Navigator when a user places the mouse pointer over the anchor. In the following example, the onMouseOver event handler provides the custom message "Click this if you dare." Click me

See onClick for an example of using onMouseOver when the <A> tag's HREF attribute is set dynamically.

onSelect event handler

A select event occurs when a user selects some of the text within a text or textarea field. The onSelect event handler executes JavaScript code when a select event occurs.

See the relevant objects for the onSelect 语法.

Event Handler of

text, textarea

例子

The following example uses an onSelect handler in the valueField text object to call the selectState() function. <INPUT TYPE="text" VALUE="" NAME="valueField" onSelect="selectState()">

onSubmit event handler

A submit event occurs when a user submits a form. The onSubmit event handler executes JavaScript code when a submit event occurs.

You can use the onSubmit event handler to prevent a form from being submitted; to do so, put a return statement that returns false in the event handler. Any other returned value lets the form submit. If you omit the return statement, the form is submitted.

See the relevant objects for the onSubmit 语法.

Event Handler of

form

例子

In the following example, the onSubmit event handler calls the formData() function to evaluate the data being submitted. If the data is valid, the form is submitted; otherwise, the form is not submitted. form.onSubmit="return formData(this)"

相关 the 例子 for the form object.

相关

submit object

submit method

onUnload event handler

An unload event occurs when you exit a document. The onUnload event handler executes JavaScript code when an unload event occurs.

Use the onUnload event handler within either the <BODY> or the <FRAMESET> tag, for example, <BODY onUnload="...">.

In a <FRAMESET> and <FRAME> relationship, an onUnload event within a frame (placed in the <BODY> tag) occurs before an onUnload event within the <FRAMESET> (placed in the <FRAMESET> tag).

Event Handler of

window

例子

In the following example, the onUnload event handler calls the cleanUp() function to perform some shut down processing when the user exits a web page: <BODY onUnload="cleanUp()">

相关

onLoad event handler

open method (document object)

Opens a stream to collect the output of write or writeln methods.

语法document.open(["mimeType"])

mimeType specifies any of the following document types: text/htm

text/plain

image/gif

image/jpeg

image/x-bitmap

plugIn

plugIn is any two-part plug-in MIME type that Netscape supports.

Method of

document

Description

The open method opens a stream to collect the output of write or writeln methods. If the mimeType is text or image, the stream is opened to layout; otherwise, the stream is opened to a plug-in. If a document exists in the target window, the open method clears it.

End the stream by using the document.close() method. The close method causes text or images that were sent to layout to display. After using document.close(), issue document.open() again when you want to begin another output stream.

mimeType is an optional argument that specifies the type of document to which you are writing. If you do not specify a mimeType, the open method assumes text/htm by default.

Following is a description of mimeType:

text/htm specifies a document containing ASCII text with htm formatting.

text/plain specifies a document containing plain ASCII text with end-of-line characters to delimit displayed lines.

image/gif specifies a document with encoded bytes constituting a GIF header and pixel data.

image/jpeg specifies a document with encoded bytes constituting a JPEG header and pixel data.

image/x-bitmap specifies a document with encoded bytes constituting a bitmap header and pixel data.

plugIn loads the specified plug-in and uses it as the destination for write and writeln methods. For example, "x-world/vrml" loads the VR Scout VRML plug-in from Chaco Communications, and "application/x-director" loads the Macromedia Shockwave plug-in.

例子The following function calls document.open() to open a stream before issuing a write method: function windowWriter1() {

var myString = "Hello, world!"

msgWindow.document.open()

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

msgWindow.document.close()

}

In the following example, the probePlugIn() function determines whether a user has the Shockwave plug-in installed: function probePlugIn(mimeType) {

var havePlugIn = false

var tiny = window.open("", "teensy", "width=1,height=1")

if (tiny != null) {

if (tiny.document.open(mimeType) != null)

havePlugIn = true

tiny.close()

}

return havePlugIn

}

var haveShockwavePlugIn = probePlugIn("application/x-director")

相关

clear, close, write, writeln methods

open method (window object)

Opens a new web browser window.

语法[windowVar = ][window].open("URL", "windowName", ["windowFeatures"])

windowVar is the name of a new window. Use this variable when referring to a window's properties, methods, and containership.

URL specifies the URL to open in the new window. See the location object for a description of the URL components.

windowName is the window name to use in the TARGET attribute of a <FORM> or <A> tag. windowName can contain only alphanumeric or underscore (_) characters.

windowFeatures is a comma-separated list of any of the following options and values: toolbar[=yes|no]|[=1|0]

location[=yes|no]|[=1|0]

directories[=yes|no]|[=1|0]

status[=yes|no]|[=1|0]

menubar[=yes|no]|[=1|0]

scrollbars[=yes|no]|[=1|0]

resizable[=yes|no]|[=1|0]

width=pixels

height=pixels

You may use any subset of these options. Separate options with a comma. Do not put spaces between the options.

pixels is a positive integer specifying the dimension in pixels.

Method of

window

Description

The open method opens a new web browser window on the client, similar to choosing New Web Browser from the File menu of the Navigator. The URL argument specifies the URL contained by the new window. If URL is an empty string, a new, empty window is created.

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

windowFeatures is an optional, comma-separated list of options for the new window. The boolean windowFeatures options are set to true if they are specified without values, or as yes or 1. For example, open("", "messageWindow", "toolbar") and open("", "messageWindow", "toolbar=1") both set the toolbar option to true. If windowName does not specify an existing window and you do not specify windowFeatures, all boolean windowFeatures are true by default. If you specify any item in windowFeatures, all other Boolean windowFeatures are false unless you explicitly specify them.

Following is a description of the windowFeatures:

toolbar creates the standard Navigator toolbar, with buttons such as "Back" and "Forward", if true

location creates a Location entry field, if true

directories creates the standard Navigator directory buttons, such as "What's New" and "What's Cool", if true

status creates the status bar at the bottom of the window, if true

menubar creates the menu at the top of the window, if true

scrollbars creates horizontal and vertical scrollbars when the document grows larger than the window dimensions, if true

resizable allows a user to resize the window, if true

width specifies the width of the window in pixels

height specifies the height of the window in pixels

例子

In the following example, the windowOpener function opens a window and uses write methods to display a message: function windowOpener() {

msgWindow=window.open("","displayWindow","menubar=yes")

msgWindow.document.write

("<HEAD><TITLE>Message window</TITLE></HEAD>")

msgWindow.document.write

("<CENTER><BIG><B>Hello, world!</B></BIG></CENTER>")

}

The following is an onClick event handler that opens a new client window displaying the content specified in the file sesame.htm. The window opens with the specified option settings; all other options are false because they are not specified.

Notice the use of single quotes (') inside the onClick event handler.

相关

close method

options property

An array corresponding to options in a select object (<OPTION> tags) in source order. See select 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- 王朝網路 版權所有