共用方式為


Sys.UI.DomEvent addHandlers Method

Adds a list of DOM event handlers to the DOM element that exposes the events. This member is static and can be invoked without creating an instance of the class.

Sys.UI.DomEvent.addHandlers(element, events, handlerOwner, autoRemove);

Parameters

Term

Definition

element

The DOM element that exposes the events.

events

A dictionary of event handlers.

handlerOwner

(Optional) The object instance that is the context for the delegates that should be created from the handlers.

autoRemove

(Optional) A boolean value that determines whether the handler should be removed automatically when the element is disposed.

Exceptions

Exception type

Condition

Error.invalidOperation

(Debug) One of the handlers specified in events is not a function.

Remarks

Use the addHandlers method to add a list of DOM event handlers to the element that exposes the event.

The events parameter takes a comma-separated list of name/value pairs in the format name:value, where name is the name of the DOM event and value is the name of the handler function. If there is more than one name/value pair, the list must be enclosed in braces ({}) to identify it as a single parameter. Multiple name/value pairs are separated with commas. Event names should not include the "on" prefix. For example, specify "click" instead of "onclick".

If handlerOwner is specified, delegates are created for each handler. These delegates are attached to the specified object instance, and the this pointer from the delegate handler will refer to the handlerOwner object.

This method can be accessed through the $addHandlers shortcut method.

Example

The following example shows how to associate event handlers with an element by using the addHandlers method.

<script type="text/javascript">
    Sys.UI.DomEvent.addHandlers($get("Button1"), {click:processEventInfo,mouseover:processEventInfo,mouseout:processEventInfo});

    function processEventInfo(eventElement) {
        var result = '';
        result += eventElement.type;
        $get('Label2').innerHTML = result;
    }
 </script>
<script type="text/javascript">
    Sys.UI.DomEvent.addHandlers($get("Button1"), {click:processEventInfo,mouseover:processEventInfo,mouseout:processEventInfo});

    function processEventInfo(eventElement) {
        var result = '';
        result += eventElement.type;
        $get('Label2').innerHTML = result;
    }
 </script>

See Also

Reference

Sys.UI.DomEvent Class

Other Resources

Language Reference