Home  >  Article  >  Web Front-end  >  JS implementation of event response example of OCX control_javascript skills

JS implementation of event response example of OCX control_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:36:091593browse

JS supports the events of the OCX control. When the event defined by the OCX control occurs, JS can capture the event and handle the event accordingly.

Personally understood, it is actually who will complete the event response. The OCX control itself can definitely be implemented. The mechanism provided by JS allows JS to also complete the response to the OCX control event.

A simple example is as follows:

First add custom events in the OCX control (the same applies to predefined events, such as mouse clicks, etc. I haven’t tried it myself, but the principle should be the same),

The event should belong to the window, so right-click on the Ctrl class, Add->Add Event, as shown below:

Enter the event name in the opened dialog box, such as OnChange. If parameters are required, set the parameter information and click [Finish]. The wizard will automatically generate the code, as follows

Copy code The code is as follows:

//Event mapping
BEGIN_EVENT_MAP(CH_OcxCtrl, COleControl)
EVENT_CUSTOM_ID("OnChange", eventidChange, OnChange, VTS_NONE)
END_EVENT_MAP()

Well, the event definition is completed, and then the event needs to be triggered. You can call OnChange() in a function of the OCX control to trigger the event.
The event definition of the OCX control is now completed.

The next step is the response to the event in JS, the code is as follows,

Copy code The code is as follows:



MyCtrl is the OCX control object ID of the control in this page (name seems to work, but I have not tried it). This object can be operated in javascript.
OnChange() is an event in the OCX control. The event name here must be the same as the event name in the OCX control.
If the event has parameters, when the event is triggered, the OCX control will pass the corresponding parameters. For example, the event has two parameters p1 and p2, which can be written as event = "OnChange(param1,param2)". At this time, param1 and param2 will correspond to After receiving p1 and p2, the same applies to Call(param1,param2).

Copy code The code is as follows:



It was written in a hurry, and the language expression is not very clear. The basic idea is this, just for memo.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn