CSDN博客

img longj

javascript手冊-o

发表于2001/8/27 20:02:00  941人阅读

分类: web開發

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:

    <A HREF="" onClick="this.href=pickRandomURL()" onMouseOver="window.status='Pick a random URL'; return true"> Go!</A>

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

    <A HREF="tppmsgs/msgs0.htm#17" tppabs="http://home.netscape.com/" onMouseOver="window.status='Click this if you dare!'; return true"> Click me</A>

    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.

    <FORM NAME="myform"> <INPUT TYPE="button" NAME="Button1" VALUE="Open Sesame!" onClick="window.open ('sesame.htm', 'newWin', 'scrollbars=yes,status=yes,width=300,height=300')"> </FORM>

    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.

  • 0 0

    相关博文

    我的热门文章

    img
    取 消
    img