JS implements an example of an OCX control's event response
- 2020-03-30 03:57:59
- OfStack
Personal understanding, in fact, is the response to the event by who to complete, OCX control itself is certainly able to achieve, JS provides this mechanism to enable JS to complete the OCX control event response.
Simple examples are as follows:
First, add custom events in the OCX control (the same for predefined events, such as mouse clicks, etc., without trying it personally, the principle should be the same),
Events should belong to the window, so right-click on the Ctrl class, Add-> Add Event, as shown below:
Enter the name of the event, such as OnChange, in the dialog box that opens. If you need parameters, set the parameter information, click [finish], and the wizard automatically generates the code, as shown below
//Event mapping
BEGIN_EVENT_MAP(CH_OcxCtrl, COleControl)
EVENT_CUSTOM_ID("OnChange", eventidChange, OnChange, VTS_NONE)
END_EVENT_MAP()
Now that the event is defined, you need to trigger the event by calling OnChange() in one of the OCX controls.
This completes the event definition for the OCX control.
Next is the response to the event in JS, 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 OCX control object ID of the control in this page (name seems to work as well, not tried), which can be manipulated in javascript.
OnChange() is an event in the OCX control, where the event name must be the same as the event name in the OCX control.
If the event has parameters, the OCX control will pass the corresponding parameters when the event is triggered. 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 receive p1 and p2 correspondingly.
<script type="text/javascript" Language=Javascript>
function Call(param1,param2)
{
alert(param1+param2); //Operation code
}
</script>
Write hastily, language expression is not very clear, the basic idea is like this, for memos.