JS Event Response example for implementing the OCX control
JS supports events of the OCX control. When an event defined by the OCX control occurs, JS can capture the event and process the event accordingly.
In my personal understanding, it is actually who will complete the event response. The OCX control itself can certainly be implemented. This mechanism provided by JS allows JS to also respond to OCX control events.
An example is as follows:
First, add custom events to the OCX control (the same is true for predefined events, such as mouse clicks. If you do not try them yourself, the principle should be the same ),
The Event should belong to the window, so right-click the Ctrl class, Add-> Add Event, such:
In the displayed dialog box, enter the event name, for example, OnChange. If you need a parameter, set the parameter information and click [finish]. The wizard automatically generates the Code as follows:
The Code is as follows:
// Event ing
BEGIN_EVENT_MAP (CH_OcxCtrl, COleControl)
EVENT_CUSTOM_ID ("OnChange", eventidChange, OnChange, VTS_NONE)
END_EVENT_MAP ()
Now, the event definition is complete. Next, you need to trigger this event. You can call OnChange () in a function of the OCX control to trigger the event.
Now the OCX control event definition is complete.
Next is the response to the event in JS. The Code is as follows,
The Code is as follows:
<Script language = "javascript" for = "MyCtrl" event = "OnChange ()" type = "text/javascript">
Call (); // You can also directly write the operation code.
</Script>
MyCtrl is the ID of the OCX control object of the control on this page (the name seems to be OK, but it has not been tried). You can operate on this object in javascript.
OnChange () is an event in the OCX control. The event name must be the same as the event name in the OCX control.
If the event contains parameters, the OCX control will pass the relevant parameters when an event is triggered. For example, the event contains two parameters p1 and p2, which can be written as event = "OnChange (param1, param2) at this time, param1 and param2 will receive p1 and p2, and Call (param1, param2) is the same ).
The Code is as follows:
<Script type = "text/javascript" Language = Javascript>
Function Call (param1, param2)
{
Alert (param1 + param2); // operation code
}
</Script>
In the rush of writing, the language expression is not very clear, and the basic idea is this, used for memo.