事件处理

 

事件处理

以下的事件可由 JavaScript 发生:

  • onBlur
  • onChange
  • onClick
  • onFocus
  • onLoad
  • onMouseOver
  • onSelect
  • onSubmit
  • onUnload

    onBlur event handler

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

    Applies to

    selection, text, textArea

    Examples

    xxx Examples to be supplied.


    onChange event handler

    A change event occurs when a selection, 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.

    Applies to

    selection, text, textArea

    Examples

    xxx Examples to be supplied.


    onClick event handler

    For button or radioButton, JavaScript code to run when a button is clicked. For checkbox, JavaScript code to run when user checks or unchecks an item.

    Applies to

    button, checkbox, radioButton, link, reset, submit

    Examples

    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 an anchor to dynamically specify a value for the HREF attribute of the anchor, as shown in the following example:

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

    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

    Executed when input focus enters the field, either by tabbing in or by clicking but not selecting in the field.

    Applies to

    selection, text, textArea

    Examples

    xxx Examples to be supplied.


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

    Applies to

    document, window

    Examples

    xxx Examples to be supplied.

    See also

    onUnload event handler


    onMouseOver event handler

    Executes when the mouse pointer is over an object. You must return true if you want to set the window.status property with the onMouseOver event handler.

    Applies to

    link

    Examples

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

       &amp;lt;A HREF="http://home.netscape.com/" onMouseOver="window.status='Click this if you dare!'; return true"&amp;gt; Click me&amp;lt;/A&amp;gt; 
     

    See onClick for an example of using onMouseOver when the anchor 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.

    Applies to

    text, textArea

    Examples

    xxx Examples to be supplied.


    onSubmit event handler

    Specifies the JavaScript code to run when a user attempts to submit a form. Return true to allow the form to be submitted; return false to prevent the form from being submitted.

    Applies to

    form

    Examples

    In the following example, the onSubmit event handler evaluates the data being submitted to test if it is legal. If the data is legal, the form is submitted; otherwise, the form is not submitted.

       form.onSubmit= "if badFormData(this.form) { return false; } else { return true; }" 
     

    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> tags, for example, <BODY onUnload="...">.

    Applies to

    document, window

    Examples

    xxx Examples to be supplied.

    See also

    onLoad event handler

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值